JOptionPane.showConfirmDialog

0
protected void thisWindowClosing(WindowEvent e)
 {
    int n = JOptionPane.showConfirmDialog(e.getWindow() , "¿DESEA CERRAR EL PROGRAMA?",
        "Confirmación", JOptionPane.YES_NO_OPTION);
     if(n==JOptionPane.YES_OPTION)
      {
       JOptionPane.showMessageDialog(null, "GRACIAS POR UTILIZAR EL PROGRAMA");
        System.exit(0);
      }
   }

When I select SI , the window closes but when I select NO the same sale closes, I would like to know how to do so that when I select NO, the window will not close.

    
asked by Bruno 27.10.2016 в 23:07
source

1 answer

0

This happens, because the JFrame have a property defaultCloseOperation windowevents by default with value EXIT_ON_CLOSE , you would have to change this property to DO_NOTHING graphically or DO_NOTHING_ON_CLOSE by code. Then, when selecting the option NO of your showConfirmDialog the JFrame is NOT closed.

To change it if it is graphic, go to the properties and locate and change its value. a Code level would be

form.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    
answered by 27.10.2016 / 23:39
source