File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Exit an GUI application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Barcodes with iOS this week in the iOS forum
or Core Java for the Impatient in the Java 8 forum!

JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Exit an GUI application" Watch "Exit an GUI application" New topic

Exit an GUI application

Maarten aan de Stegge

Joined: Jun 03, 2004
Posts: 3
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

Joined: Oct 29, 2001
Posts: 9043

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.

[How To Ask Questions On JavaRanch]
Maarten aan de Stegge

Joined: Jun 03, 2004
Posts: 3
You can set what a JFrame does when you close it. To get the behavior you want, do this:


Then, when you close the JFrame, your program will end.
I agree. Here's the link:
subject: Exit an GUI application