OnExit Event For a Swing Application?

exit, java, swing

Solution

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

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

Problem

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?

Original source