Java - how do I prevent WindowClosing from actually closing the window

后端 未结 7 1691
灰色年华
灰色年华 2020-12-03 04:23

I seem to have the reverse problem to most people. I have the following pretty standard code to see if the user wants to do some saves before closing the window:

         


        
7条回答
  •  一个人的身影
    2020-12-03 04:47

    Not sure where your problem is, but this works for me!

    frame.addWindowListener(new WindowAdapter() {
    
                public void windowClosing(WindowEvent evt) {
                                int res=JOptionPane.showConfirmDialog(null,
                                        "Do you want to exit.?");
                                if(res==JOptionPane.YES_OPTION){
                                        Cal.this.dispose();
                                }
                }                               
            });
    

提交回复
热议问题