如何關閉Java GUI而不需要System.exit?當我使用處理() GUI關閉,但在此之後它不會重新啓動?我使用圖形用戶界面來自動抓取圖像並將其寫入磁盤,因此每次啓動GUI時都需要重複此操作。後來,我想連接這個GUI以在MATLAB中啓動。沒有System.exit的情況下關閉Java GUI
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();
}
}
}
}
謝謝你的工作!現在我遇到了另一個問題,因爲每次GUI加載serial.dll時,MATLAB都會提示錯誤:「本機庫C:\ serial.dll已經加載到另一個類加載器中」。你能幫我解決嗎? – Makaroni
@Makaroni:「Native Library whatever.dll已經加載到另一個類加載器中。」似乎已經在SO上多次回答:http://stackoverflow.com/questions/3724421/native-library-already-loaded-in-another-classloader有一個答案和其他幾個鏈接。 – millimoose