获取应用程序结束事件 [英] 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.
推荐答案
您可以使用 shutdown hook 。它适用于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屋!
查看全文