Java – get application shutdown event
•
Java
How do I get to the application shutdown event?
I want to get an application to save all unsaved operations, or display a message to the user "are you sure you want to close without saving all data?" Such a thing
If this would be useful – the application is using swing's singleframeapplication
Solution
You can use shutdown hook It is suitable for swing, AWT and even console applications
Example:
Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { //do your stuff } });
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码