A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Java in General
catching the event before a java program will end . . .
Joined: Apr 02, 2009
Aug 20, 2010 00:48:53
i am not in a gui program to do something before window is closing . . .
show me, how to catch the sudden cancellation of a
but how to know before, when a jvm is exiting normally??
Joined: Jun 09, 2003
Aug 20, 2010 01:27:00
not sure I'm reading this right, but one of the ways is to set the frame's closeOperation to DO_NOTHING_ON_CLOSE,
then add your own windowListener, and in windowClosing do what you want before calling System.exit(..)
Joined: Nov 18, 2006
Aug 20, 2010 01:38:55
A window listener would react on behalf of the window. Some applications don't necessarily run in window mode. A shutdown hook would always be possible (depends on your targets/presets):
Censorship is the younger of two shameful sisters, the older one bears the name inquisition.
-- Johann Nepomuk Nestroy
Joined: Oct 27, 2005
Aug 20, 2010 06:06:25
Shutdown hooks are indeed the way to go. They will only not be called if the JVM is terminated forcefully (e.g. using Runtime.getRuntime().halt(), or by killing the process from the operating system)
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions
How To Answer Questions
Joined: Oct 13, 2005
Aug 21, 2010 02:16:41
is probably a more helpful link about shutdown hooks; note it is a bit old however.
Another (also old) link
Shutdown hooks are nice things
I agree. Here's the link:
subject: catching the event before a java program will end . . .
validate URL in Java Program
Installing Java and setting up variables path
Extremely basic things
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2014