Search code examples
javaswingnio

Cleanup before exiting Java application


I'm writing a small Java application using Swing. The application also has a networking component.

I want to run some code before exiting(close channels, keys, etc).Is there a way to do this, without adding an Exit button in my interface, in which to do my cleanup, then do System.exit()?


Solution

  • You should be able to do what you want in windowClosing(), shown here.