【发布时间】:2011-08-17 14:43:23
【问题描述】:
如何在没有 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();
}
}
}
}
【问题讨论】:
标签: java matlab user-interface dispose