confirmation before press YES to exit program in Java

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


        
3条回答
  •  抹茶落季
    2021-02-11 04:52

    addWindowListener(new WindowAdapter(){
                public void windowClosing(WindowEvent evt){
                    int x = JOptionPane.showConfirmDialog(null, 
                        "Are you sure you want to exit ?", "Comform !",
                        JOptionPane.YES_NO_OPTION);
    
                    if(x == JOptionPane.YES_OPTION) {
                        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                    }else{
                        setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
                    }
                }
            });
    

    Chek this.

提交回复
热议问题