Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How do I exit an AWT root frame without calling System.exit()?  RSS feed

 
Michael Yuan
author
Ranch Hand
Posts: 1427
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I guess this is a trival question but I just could not figure out a way ... Any comments will be greated appreciated.
I was trying to add a "close" button to an AWT frame. Once it is clicked, the frame should exit. But I do not want to exit the entire JVM since the frame is started by a console program that needs to continue running. How do I do it? The Frame class does not see to have a "close()" function. (The dispose() function only frees native resources and do not close the window).
Of course, I could use the "close window" icon provided by the operating syste, But that is kinda ugly. Can I do that with a button? Thanks
 
Manish Hatwalne
Ranch Hand
Posts: 2596
Android Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Michael,
Not very sure about what you mean by "Close" window, but I think dispose() should do what you require. It does close the window.
Here is description from its API doc -
Releases all of the native screen resources used by this Window, its subcomponents, and all of its owned children. That is, the resources for these Components will be destroyed, any memory they consume will be returned to the OS, and they will be marked as undisplayable.
The Window and its subcomponents can be made displayable again by rebuilding the native resources with a subsequent call to pack or show. The states of the recreated Window and its subcomponents will be identical to the states of these objects at the point where the Window was disposed (not accounting for additional modifcations between those actions).

If you just want to hide the Frame, you can use setVisible(false).
HTH,
- Manish
 
Michael Yuan
author
Ranch Hand
Posts: 1427
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have not tried "dispose()" under windows. But on the Mac OS X and even Pocket PC (IBM J9 Personal Profile) platforms, "dispose()" causes the window to disappear for a second and then the VM re-draws the window. (No, I did not call "show()" or "pack()" after "dispose()" .
Maybe those are problems with the AWT implementation on Mac OS X and IBM J9? I will try it under Sun JDK for windows. Will post results later.
cheers
Michael
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!