Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

execute a class Before Window is shutting down

Posted on 2002-06-21
9
Medium Priority
?
188 Views
Last Modified: 2010-03-31
Hi, as question title, how do i execute a class before Window is shutting down? Can i do that? Thanks
0
Comment
Question by:chencc77
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 1

Expert Comment

by:googlyralph
ID: 7098322
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
 

Author Comment

by:chencc77
ID: 7098350
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
 
LVL 1

Expert Comment

by:googlyralph
ID: 7098361
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 92

Accepted Solution

by:
objects earned 200 total points
ID: 7098369
Try using addShutdownHook() method in runtime class:

Runtime.getRuntime().addShutdownHook(mythread);
0
 

Author Comment

by:chencc77
ID: 7098377
i see. Thanks googlyralph. ^-^
0
 
LVL 1

Expert Comment

by:googlyralph
ID: 7098378
If the JVM is running all the time, the go for Objects idea.

GR.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 7098414
listening...
0
 

Author Comment

by:chencc77
ID: 7098525
Thanks, it works.
0
 
LVL 92

Expert Comment

by:objects
ID: 7099700
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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question