Link to home
Start Free TrialLog in
Avatar of chencc77
chencc77

asked on

execute a class Before Window is shutting down

Hi, as question title, how do i execute a class before Window is shutting down? Can i do that? Thanks
Avatar of googlyralph
googlyralph

You can add code to the window adapter that handles events connected with closing a window. This allows things like "are you sure you want to exit" type dialogs, as well as any other code. Look up the class, WindowAdapter in the Java API documentation.

GR.
Avatar of chencc77

ASKER

Hi, I don't mean my java program can shut down the pc. But the program itself only auto execute when the pc is going to shut down.
From Java im not sure. You will need to register an interest with the system for an on shutdown event. Check the Microsoft Java API, but i doubt there will be anything there. Failing that look up on MSDN (msdn.microsoft.com) about registering an interest in system shutdown event. Then you will need to write some jni code that watchs for a system shutdown and passes on the information to the Java code.

(Assuming you are talking about Windows that is)

GR.
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
i see. Thanks googlyralph. ^-^
If the JVM is running all the time, the go for Objects idea.

GR.
listening...
Thanks, it works.