File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Closing program when GUI is closed

 
Mikpo Siru
Ranch Hand
Posts: 54
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5115
11
Java Netbeans IDE Opera
  • 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rob Spoor
Sheriff
Pie
Posts: 20393
47
Chrome Eclipse IDE Java Windows
  • 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Mikpo Siru
Ranch Hand
Posts: 54
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your suggestions.
 
Rob Spoor
Sheriff
Pie
Posts: 20393
47
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic