Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Exiting Java GUI application without using System.exit()

Reply
Thread Tools

Exiting Java GUI application without using System.exit()

 
 
MS
Guest
Posts: n/a
 
      03-04-2005
Hi,

What is the correct and safe way of exiting a Java JFrame GUI application?

My GUI has an Exit button, but while searching on this, I discovered that
System.exit(0) is not a good way to terminate the application. How should
it be done.

Thanks,

MS
 
Reply With Quote
 
 
 
 
Fahd Shariff
Guest
Posts: n/a
 
      03-04-2005
You need to explicitly call System.exit(exit_value) to exit a Swing
application.

You might however wish to perform some cleanup e.g. closing file
handles, database connections, deleting temporary files etc before
exiting.

exitButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
cleanUp();
System.exit(0);
}
});

--
Fahd Shariff
http://www.fahdshariff.cjb.net
"Let the code do the talking..."

 
Reply With Quote
 
 
 
 
MS
Guest
Posts: n/a
 
      03-04-2005
Ok, thanks.

Fahd Shariff emailed this:
> You need to explicitly call System.exit(exit_value) to exit a Swing
> application.
>
> You might however wish to perform some cleanup e.g. closing file
> handles, database connections, deleting temporary files etc before
> exiting.
>
> exitButton.addActionListener(new ActionListener() {
> public void actionPerformed(ActionEvent e) {
> cleanUp();
> System.exit(0);
> }
> });
>
> --
> Fahd Shariff
> http://www.fahdshariff.cjb.net
> "Let the code do the talking..."
>

 
Reply With Quote
 
Rhino
Guest
Posts: n/a
 
      03-04-2005
One additional point which Fahd didn't mention explicitly.

Someone told me the other day that the main objection to System.exit() is
that it will terminate other threads that are running in the application. I
was told that you should make a serious effort to stop any such threads
cleanly before attempting to do the System.exit().

Rhino

"MS" <matthews@mailsnare.---nojunktakeout---.net> wrote in message
news:5%0Wd.28441$(E-Mail Removed) .uk...
> Ok, thanks.
>
> Fahd Shariff emailed this:
> > You need to explicitly call System.exit(exit_value) to exit a Swing
> > application.
> >
> > You might however wish to perform some cleanup e.g. closing file
> > handles, database connections, deleting temporary files etc before
> > exiting.
> >
> > exitButton.addActionListener(new ActionListener() {
> > public void actionPerformed(ActionEvent e) {
> > cleanUp();
> > System.exit(0);
> > }
> > });
> >
> > --
> > Fahd Shariff
> > http://www.fahdshariff.cjb.net
> > "Let the code do the talking..."
> >



 
Reply With Quote
 
MS
Guest
Posts: n/a
 
      03-04-2005
Thanks, no threads to stop, useful info. though.

MS

Rhino emailed this:
> One additional point which Fahd didn't mention explicitly.
>
> Someone told me the other day that the main objection to System.exit() is
> that it will terminate other threads that are running in the application. I
> was told that you should make a serious effort to stop any such threads
> cleanly before attempting to do the System.exit().
>
> Rhino
>
> "MS" <matthews@mailsnare.---nojunktakeout---.net> wrote in message
> news:5%0Wd.28441$(E-Mail Removed) .uk...
>
>>Ok, thanks.
>>
>>Fahd Shariff emailed this:
>>
>>>You need to explicitly call System.exit(exit_value) to exit a Swing
>>>application.
>>>
>>>You might however wish to perform some cleanup e.g. closing file
>>>handles, database connections, deleting temporary files etc before
>>>exiting.
>>>
>>>exitButton.addActionListener(new ActionListener() {
>>> public void actionPerformed(ActionEvent e) {
>>> cleanUp();
>>> System.exit(0);
>>> }
>>> });
>>>
>>>--
>>>Fahd Shariff
>>>http://www.fahdshariff.cjb.net
>>>"Let the code do the talking..."
>>>

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
PyGTK GUI update without signals from GUI Andrew Lapidas Python 0 04-12-2008 11:07 PM
Runtime.getRuntime.exec() without exiting the main program knguyen Java 9 02-15-2008 07:33 PM
How do I stop Python IDLE (GUI) from immediately exiting when I enter it? John (Z R) L Python 6 11-21-2006 07:17 PM
PythonWin: any way to delete all objects without exiting and without doing it with "del"? dananrg@yahoo.com Python 5 03-03-2006 05:12 PM
How to make the program connect to next IP address without exiting program, if the current connection fail?? Abby C Programming 1 08-29-2003 03:08 AM



Advertisments