Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

execute a class Before Window is shutting down

Posted on 2002-06-21
9
Medium Priority
?
186 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
The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

 
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

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

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 …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

705 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