jf.addWindowListener(new WindowAdapter() {
public void windowOpened( WindowEvent e ){
in.requestFocus(); //獲取焦點
}
public void windowClosing(WindowEvent e) {
int result = JOptionPane.showConfirmDialog(null, "是否要退出?", "退出確認", JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE);
if (result == JOptionPane.YES_OPTION)
System.exit(0);
}
});
jf是Jframe對象,in是JTextField對象
// 當窗口關閉時,需要釋放串口資源。
this.addWindowListener(new WindowAdapter() {
public void windowOpened( WindowEvent e ){
in.requestFocus(); //獲取焦點
}
public void windowClosing(WindowEvent arg0) {
if (JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(
FileEntry.this, "是否要退出?", "警告",
JOptionPane.YES_NO_OPTION)) {
System.out.println("system closed");
System.exit(0);
}
}
});