Java

Moderators: zibadian
Number of threads: 7836
Number of posts: 18235

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
problems with windowClosing in windowAdapter Posted by yanghui1023 on 18 Oct 2006 at 7:15 AM
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,do 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!




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.