我想要做的就是使用FileChooser
來選擇路徑。如何等待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 ");
}
你想閱讀關於「模態」對話框。在這裏看到,例如:https://docs.oracle.com/javase/tutorial/uiswing/components/filechooser.html – GhostCat
你的意思是這一個HTTPS:?//docs.oracle.com/javase/tutorial/uiswing/misc /modality.html –
開始由具有看看[如何使用文件挑肥揀瘦(https://docs.oracle.com/javase/tutorial/uiswing/components/filechooser.html) – MadProgrammer