Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

problems with windowClosing in windowAdapter

843805Oct 18 2006 — edited Oct 18 2006
hello,
I used JFrame and want to add windowlistener to a JFrame object.I overrided the windowClosing method in windowAdapter.But I don't want the JFrame object always closed. I want the system will exit in some cases,and the system won't in other cases.
My code:
this.addWindowListener(new java.awt.event.WindowAdapter() {
       public void windowClosing(java.awt.event.WindowEvent e){
          if (isModified==true) { //there are some changes of the file
              String message="Your file has been modified�Cdo you want  to save the changes?";
              int result=JOptionPane.showConfirmDialog(this, message, "save?", JOptionPane.YES_NO_CANCEL_OPTION );
              if (result==JOptionPane.CANCEL_OPTION) { //don't exit
                   return; //don't really exit
              } else if (result==JOptionPane.YES_OPTION){ //  
                   save();  //the save block 
              }else {  //I dont want to save the changes
                  System.exit(0);
              }
          }else { // there are't any changes of the file
                    System.exit(0);
          }
     } 
 });
I watched the task manager.In fact,if just override the windowClosing method while do nothing in the method ,such as:
this.addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent e){
                
            } 
        });
The frame don't really been killed but it still owns resources, but I can't see the JFrame object.
Can anyone tell me the reason? How can I kill the frame in some cases when the windowClosing method is called while the freme is not killed and can be seen in some cases?
Thanks!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 15 2006
Added on Oct 18 2006
2 comments
98 views