I want to make my Java Application to call my own custom made function when the "close" cross button is pressed. as far as i see there may be no way since setDefaultCloseOperation
has no overloads at all.
Any idea how this can be achieved?
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);