I'm having an issue with my application regarding quitting. What I want is for it to perform a task of my choosing before it quits, no matter how it is exited. (aside from the force quit in Task Manager and or Activity Monitor of course) I've successfully managed to have my app perform this task when the "X" button is pressed. Code for that:
WindowListener exitListener = new WindowAdapter(){
@Override
public void windowClosing(WindowEvent e){
int confirm = JOptionPane.showOptionDialog
(null, "Are You Sure You Want to Close Application?",
"Exit Confirmation", JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE, null, null, null);
if (confirm == 0){
ProcessCommand pc = new ProcessCommand();
if(sRunning){
pc.sendText("stop");
}
System.exit(0);
}
}
};
frame.addWindowListener(exitListener);
That works wonderfully until I press Cmd+Q(Apple) or Alt+F4 (Windows). How would I go about handling those two events in a similar manner?