Show prompt before closing JFrame
java, swing
Solution
What is your JFrame's default close operation set to? You need to make sure that it been set to: `jFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);`
Problem
I am using `windowClosing` to confirm before closing a particular JFrame. Before closing I get a confirm dialog but the problem is it closes even if I click the NO button. Any help please? ``` addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent we) { String ObjButtons[] = {"Yes","No"}; int PromptResult = JOptionPane.showOptionDialog(null, "Are you sure you want to exit?", "Online Examination System", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, ObjButtons,ObjButtons[1]); if(PromptResult==0) { System.exit(0); } } }); ```