Solved

execute a class Before Window is shutting down

Posted on 2002-06-21
9
182 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
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!

 
LVL 92

Accepted Solution

by:
objects earned 50 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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
eclipse buid path vs tomcat lib path 10 49
String array comparison 4 57
ejb entity bean example issue 2 43
American Express @Work site and Java 4 95
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

734 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