confirmation before press YES to exit program in Java

后端 未结 3 930
悲哀的现实
悲哀的现实 2021-02-11 04:17
private void windowClosing(java.awt.event.WindowEvent evt)                               
    {                                   
        int confirmed = JOptionPane.sh         


        
3条回答
  •  后悔当初
    2021-02-11 04:50

    Try this, it's working for me.

    private void windowClosing(java.awt.event.WindowEvent evt) {                                   
        int confirmed = JOptionPane.showConfirmDialog(null, "Exit Program?","EXIT",JOptionPane.YES_NO_OPTION);
        if(confirmed == JOptionPane.YES_OPTION)
        {
            dispose();
        }
    } else {
         setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    

提交回复
热议问题