I have a JFrame which I want to press the "X" key (close the JFrame) to confirm if I really want to close the application or not. If I click "NO", it closes the application.
Why doesn't it work if I select "NO"?
setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent evt){
if (JOptionPane.showConfirmDialog(rootPane, "Confirm out?",
"AppLocal", JOptionPane.ERROR_MESSAGE) == JOptionPane.ERROR_MESSAGE){
dispose();
}
}
});