| 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
|
|
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
|
 |
 |
|
|
subject: Closing program when GUI is closed
|
|
|