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?
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.
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.
Runtime.getRuntime().addShutdownHook(new Thread()
{
@Override
public void run()
{
updateZonas();
db.close();
}
});
This works for any Java application(Swing/AWT/Console)
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