This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exit an GUI application

 
Paul Steko
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a GUI application which displays three different messages for a period of 5 seconds in the same JTextArea. When I close the window before de second or third message is displayed the thread is still being executed in the �DOS Window�. Is it possible to stop the tread (and the entire program) when de GUI is closed?

I use the following code:

 
Joe Ess
Bartender
Posts: 9279
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by aan de Stegge Maarten:



Well, there isn't a listener for the window closing event until after your ExitTest constructor runs it's course, so I'd say no.
 
Paul Steko
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can set what a JFrame does when you close it. To get the behavior you want, do this:

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

Then, when you close the JFrame, your program will end.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic