开发者

Swing application - resource clean up should be done in windowClosing or windowClosed

开发者 https://www.devze.com 2023-01-20 01:01 出处:网络
In Swing application, I was wondering all the resource cleanup jobs, like : network resource shutdow开发者_如何学Pythonn, stopping thread, closing file handles...

In Swing application, I was wondering all the resource cleanup jobs, like : network resource shutdow开发者_如何学Pythonn, stopping thread, closing file handles...

Should it be done in windowClosed or windowClosing ?

Thanks.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消