maybe this one, but before that read tutorial WindowListener posted by Howard, there are some/another options
WindowListener exitListener = new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
int confirm = JOptionPane.showOptionDialog(
null, "Are You Sure to Close Application?",
"Exit Confirmation", JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE, null, null, null);
if (confirm == 0) {
System.exit(0);
}
}
};
frame.addWindowListener(exitListener);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…