I want to prompt the user for a confirmation when they want to close the frame window, like so:
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
if (JOptionPane.showConfirmDialog(null, "Are you sure you want to abort the game?",
"Really quit?", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
dispose();
}
});
The dialog shows up but the window closes no matter if I click yes, no, or close the window. Is this some sort of bug or am I really missing something simple here? I'm using Eclipse on OS X with Java 1.6.0.13.