PDA

View Full Version : Java terminal/command line



sb89
23-03-11, 18:49
I have a Java program that runs on the terminal. Is there any way of calling code when the user closes the window just before the terminal closes?

iGoD ReLeNtLeS
23-03-11, 19:04
i believe you can use the addShutdownHook, i think thats what you on about. To execute some code when the terminal window is closed or its stopped using Ctrl + C

http://download.oracle.com/javase/6/docs/api/java/lang/Runtime.html#addShutdownHook%28java.lang.Thread%29

Try that ;)

benzeman
23-03-11, 19:09
Don't think you'll be able to as you could add code to make unclosable windows by making a new one when the old one is closed?

sb89
23-03-11, 20:06
i believe you can use the addShutdownHook, i think thats what you on about. To execute some code when the terminal window is closed or its stopped using Ctrl + C

http://download.oracle.com/javase/6/docs/api/java/lang/Runtime.html#addShutdownHook%28java.lang.Thread%29

Try that ;)

Cheers, that worked.