【发布时间】:2015-09-07 07:58:50
【问题描述】:
我想要做的是使用FileChooser 来选择路径。
选择后,路径应由以下实例使用。
我的问题是如何强制一切都在路径上等待,否则程序只是在没有等待的情况下运行。
//GUI
JFrame frame = new JFrame("Window");
FileChooser panel = new FileChooser();
frame.addWindowListener(
new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
}
);
frame.getContentPane().add(panel,"Center");
frame.setSize(panel.getPreferredSize());
frame.setVisible(true);
if(panel.getPath() == null){
}
String path = panel.getPath();
//some additional stuff that does not need any pathinformation
.......
//next step calculation which runs without waiting
Calculation calc = new Calculation();
calc.run(path);
提前致谢
附:
这是我的 ActionListner 包含的内容
if (result == JFileChooser.CANCEL_OPTION) {
System.out.println("Cancel was selected");
}
else if (result == JFileChooser.APPROVE_OPTION) {
path = chooser.getSelectedFile().getAbsolutePath();
System.out.println("getCurrentDirectory(): "
+ chooser.getCurrentDirectory());
System.out.println("getSelectedFile() : "
+ chooser.getSelectedFile());
}
else {
System.out.println("No Selection ");
}
【问题讨论】:
-
您想了解“模态”对话框。例如,请参见此处:docs.oracle.com/javase/tutorial/uiswing/components/…
-
@JürgenK。我认为他们的意思是How to Make Dialogs
标签: java path selection wait filechooser