解决这个同时加上代理,然后在.m文件中给textfield设置代理
self.textfield.delegate=self
再用一个代段弊顷理方法
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated]// 1
[self.textField becomeFirstResponder]/握陆/ 2
}
1是调用父卜橘类代理方法,2是将textfield设成第一响应者,就OK了
运行以下代码试试看。public static void main(String[] args) {
Frame frame = new Frame("打开文件窗口")
frame.setLayout(new FlowLayout(FlowLayout.CENTER))
frame.setBounds(100, 200, 400, 300)
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
System.exit(0)
}
})
final TextField txtField = new TextField(50)
Button button = new Button("册笑打开指定文稿姿滑件")
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String path = txtField.getText()
System.out.println(path)
if (path.length() == 0) {
return
}
try {
Runtime.getRuntime().exec("explorer.exe /键腊n, " + path)
} catch (IOException ex) {
ex.printStackTrace()
}
}
})
frame.add(txtField)
frame.add(button)
frame.setVisible(true)
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)