获取应用关闭事件 [英] Get the application closing event
本文介绍了获取应用关闭事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何进入应用关闭事件?
How to get to the application closing event?
我想让应用程序保存所有未保存的操作或向用户显示一条消息您确定要关闭而不保存所有数据吗?"像这样的东西.
I want to get application to save all unsaved operations or show the user a message "Are you sure about closing without saving all data?" something like this.
如果这会有所帮助 - 该应用程序是一个使用 Swing 的 SingleFrameAplication
.
If this will be helpful - the application is a SingleFrameAplication
using Swing.
推荐答案
您可以使用 关闭钩子.它适用于 Swing、AWT 甚至控制台应用程序.
You could use a shutdown hook. It works for Swing, AWT and even console applications.
示例:
Runtime.getRuntime().addShutdownHook(new Thread()
{
@Override
public void run()
{
//do your stuff
}
});
这篇关于获取应用关闭事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文