Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OnExit Event For a Swing Application?

Tags:

java

exit

swing

I'm developing a simple application to manage the operational part of a business using Swing, but I need that when the application exits, it performs this:

updateZonas();
db.close();

But how can I do this?

like image 872
Nathan Campos Avatar asked Mar 18 '10 01:03

Nathan Campos


People also ask

What is swing on an application?

Swing in java is part of Java foundation class which is lightweight and platform independent. It is used for creating window based applications. It includes components like button, scroll bar, text field etc.

What is dispose in Java?

Annotation Type DisposesA disposer method allows the application to perform customized cleanup of an object returned by a producer method or producer field. A disposer method must be a non-abstract method of a managed bean class or session bean class. A disposer method may be either static or non-static.


1 Answers

Runtime.getRuntime().addShutdownHook(new Thread()
{
    @Override
    public void run()
    {
        updateZonas();
        db.close();
    }
});

This works for any Java application(Swing/AWT/Console)

like image 137
Santhosh Kumar Tekuri Avatar answered Nov 04 '22 01:11

Santhosh Kumar Tekuri