Solved

execute a class Before Window is shutting down

Posted on 2002-06-21
9
177 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 92

Accepted Solution

by:
objects earned 50 total points
Comment Utility
Try using addShutdownHook() method in runtime class:

Runtime.getRuntime().addShutdownHook(mythread);
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:chencc77
Comment Utility
i see. Thanks googlyralph. ^-^
0
 
LVL 1

Expert Comment

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

GR.
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
listening...
0
 

Author Comment

by:chencc77
Comment Utility
Thanks, it works.
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
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 …

762 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now