OnExit Event For a Swing Application?

丶灬走出姿态 提交于 2019-11-29 01:27:23
Santhosh Kumar Tekuri
Runtime.getRuntime().addShutdownHook(new Thread()
{
    @Override
    public void run()
    {
        updateZonas();
        db.close();
    }
});

This works for any Java application(Swing/AWT/Console)

Are you using a JFrame? if so you can try this:

    myframe.addWindowListener(new java.awt.event.WindowAdapter() {
        public void windowClosing(WindowEvent winEvt) {
            updateZonas();
            db.close();
            System.exit(0);
        }
    });

Add a WindowListener to your JFrame. Its windowClosing method would call whatever code you need, then System.exit(0) (or some other return code).

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!