Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 191
  • Last Modified:

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
0
chencc77
Asked:
chencc77
  • 3
  • 3
  • 2
  • +1
1 Solution
 
googlyralphCommented:
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.
0
 
chencc77Author Commented:
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.
0
 
googlyralphCommented:
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.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
objectsCommented:
Try using addShutdownHook() method in runtime class:

Runtime.getRuntime().addShutdownHook(mythread);
0
 
chencc77Author Commented:
i see. Thanks googlyralph. ^-^
0
 
googlyralphCommented:
If the JVM is running all the time, the go for Objects idea.

GR.
0
 
CEHJCommented:
listening...
0
 
chencc77Author Commented:
Thanks, it works.
0
 
objectsCommented:
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now