开发者

Closing a Swing Frame, user vs system initiated close. How to tell the difference?

开发者 https://www.devze.com 2023-04-07 01:52 出处:网络
When the user clicks the x to close the frame, I want to take one action. When Windows shuts down and triggers a close however, I wish to take a different action. Naturally, I will be using DO_NOTHING

When the user clicks the x to close the frame, I want to take one action. When Windows shuts down and triggers a close however, I wish to take a different action. Naturally, I will be using DO_NOTHING_ON_CLOSE开发者_StackOverflow社区 or HIDE_ON_CLOSE and I know how to capture the event. All I need is "who" initiated it.


A WindowListener will tell you when the user did something that affects a window, but abrupt termination of the JVM may produce no window events at all. You may be looking for the Runtime method, addShutdownHook(), discussed here and here.

0

精彩评论

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