当我要终止该计划时,我该如何采取行动。
例如:
当我要终止程序时,我想设置
if( the x button is clicked or something )
deleteRow from database;
else
just end.
应该在ui框架内完成吗?
答案 0 :(得分:1)
使用窗口侦听器。 windowClosing
方法用于在窗口关闭时执行代码,如果您想在窗口关闭后执行某些操作,可以使用windowClosed
方法。
JFrame window=new JFrame("Window");
window.addWindowListener(new WindowAdapter(){
@Override
public void windowClosed(WindowEvent evt)
{
//Do something after window has closed.
}
public void windowClosing(WindowEvent evt)
{
//Do something when window is closing.
//Useful when you have to access data in window(buttons, textfields etc)
}
});
还有其他窗口事件侦听器。Documentation of WindowListener
答案 1 :(得分:0)
addWindowListener(new WindowAdapter()
{
@Override
public void windowClosing(WindowEvent e)
{
.....
}
});