tags:

views:

41

answers:

1

In Swing application, I was wondering all the resource cleanup jobs, like : network resource shutdown, stopping thread, closing file handles...

Should it be done in windowClosed or windowClosing ?

Thanks.

+4  A: 

Use windowClosed, because it's invoked when the window has been closed. windowClosing gets invoked whenever the "X" in the window corner is clicked, even if you had defined something like DO_NOTHING_ON_CLOSE as the closing action.

A common thing to do is to set the default closing action to DO_NOTHING_ON_CLOSE, add a WindowClosingListener to the window, and there show some kind of "Do you really want to quit?" message box. If yes, then dispose the window, if no, then do nothing.

Joonas Pulakka