如何在没有 System.exit 的情况下关闭 Java GUI?当我使用 dispose() 时,GUI 会关闭,但之后它不会再次启动?我正在使用 GUI 自动抓取图像并将其从相机写入磁盘,因此每次启动 GUI 时我都需要重复此操作。稍后,我想连接这个 GUI 以在 MATLAB 中启动。
public class MainWindow {
int fs_c = 1;
MainWindow() {
JFrame main_f = new JFrame("GUI");
main_f.getContentPane().setLayout(new BorderLayout());
main_f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
main_f.getContentPane().add(tabPane1, "Center");
//main_f.setSize(500, 620);
main_f.pack();
main_f.setVisible(true);
commandVal = 0;
while (true) {
if (fs_c == 1) {
commandVal = 5;
}
if (commandVal == 5 || commandVal == 6) {
cImage.sendFrame(0);
JFileChooser save_d = new JFileChooser();
File saveFile = save_d.getSelectedFile();
cImage.writeImage(saveFile + ".jpg");
fs_c = 0;
main_f.dispose();
} else if (commandVal == -1) {
stopCameraStuff();
}
}
}
}
最佳答案
您还应该以某种方式中断 while 循环,以便该方法可以完成并返回给调用者。
关于java - 在没有 System.exit 的情况下关闭 Java GUI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7094740/