How to get to the application closing event?
I want to get application to save all unsaved operations or show the user a message "Are you sure about closing without saving all data?" something like this.
If this will be helpful - the application is a SingleFrameAplication
using Swing.
The Closing event occurs as the form is being closed. When a form is closed, all resources created within the object are released and the form is disposed. If you cancel this event, the form remains opened.
The event FormClosing() is triggered any time a form is to get closed. To detect if the user clicked either X or your CloseButton, you may get it through the sender object.
You could use a shutdown hook. It works for Swing, AWT and even console applications.
Example:
Runtime.getRuntime().addShutdownHook(new Thread()
{
@Override
public void run()
{
//do your stuff
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With