Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the application closing event

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.

like image 836
Bulit Avatar asked Feb 16 '12 19:02

Bulit


People also ask

Which event that has happen when you close your form?

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.

Which event value is passed when close button in the window is triggered?

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.


1 Answers

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
    }
});
like image 181
c0dehunter Avatar answered Oct 25 '22 21:10

c0dehunter