Forums Register Login

catching the event before a java program will end . . .

+Pie Number of slices to send: Send
i am not in a gui program to do something before window is closing . . .

http://www.rgagnon.com/javadetails/java-0459.html show me, how to catch the sudden cancellation of a java program.

but how to know before, when a jvm is exiting normally??
+Pie Number of slices to send: Send
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(..)
+Pie Number of slices to send: Send
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):
http://download.oracle.com/javase/1.5.0/docs/api/java/lang/Runtime.html#addShutdownHook%28java.lang.Thread%29
http://cupi2.uniandes.edu.co/site/images/recursos/javadoc/j2se/1.5.0/docs/api/java/lang/Runtime.html#addShutdownHook%28java.lang.Thread%29
+Pie Number of slices to send: Send
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)
+Pie Number of slices to send: Send
This 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 do some of my very best work in water. Like this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1103 times.
Similar Threads
Java versions
validate URL in Java Program
Installing Java and setting up variables path
Extremely basic things
JAVA_HOME variable
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 19, 2024 02:44:10.