aspose file tools
The moose likes Swing / AWT / SWT and the fly likes Closing program when GUI is closed Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply Bookmark "Closing program when GUI is closed" Watch "Closing program when GUI is closed" New topic
Author

Closing program when GUI is closed

Mikpo Siru
Ranch Hand

Joined: Apr 09, 2009
Posts: 54
Hi,

I have one JFrame running in my program, and some non-gui threads. I want to perform a shutdown routine on the threads when the JFrame is closed. To do this, I have set JFrame.DISPOSE_ON_CLOSE. In another thread, I call join() on the AWT thread, so that when the AWT thread finishes (JFrame dispose()) I can excute the shutdown routines:


It seems to work. Is this a right way of doing things?

Thanks.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4203
    
    3

Depends on how insulated that code is against other classes being in the mix. All it takes is just one running Swing Timer to keep the EDT alive.

edit Additionally, setDefaultCloseOperation(...) isn't a static method.


luck, db
There are no new questions, but there may be new answers.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19232

Mikpo Siru wrote:I want to perform a shutdown routine on the threads when the JFrame is closed.

Use a WindowListener and its windowClosed method. Don't be confused with windowClosing - that's called when you press the X button to close the frame. windowClosed will be called when the window is actually closed.


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
Mikpo Siru
Ranch Hand

Joined: Apr 09, 2009
Posts: 54
Thanks for your suggestions.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19232

You're welcome
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Closing program when GUI is closed
 
Similar Threads
does this sound good/okay/terrible?
Dispose
Event Queue kills GUI
Cannot Resolve Symbol;set PreferredSize
Swing - Content Pane vs. Panel - have I got this right?