• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
author
Posts: 1436
6
Python TypeScript Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 2596
Android Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 1436
6
Python TypeScript Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic