setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); //防止点击窗口的关闭按钮退出//退出按钮事件
btnExit.addActionListener(new ActionListener ()
{
public void actionPerformed (ActionEvent e)
{
funExit ();
}
});
//***************************************************
//名称:funExit
//功能:退出确定函数
//输入:
//输出:
//返回:
//***************************************************
private void funExit ()
{
try
{
if (JOptionPane.showConfirmDialog (this, "确定要退出系统吗?", "信息", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
{
System.exit (0);
}
}
catch (Exception e)
{
System.exit (0);
System.out.println (e.getMessage ());
}
}
btnExit.addActionListener(new ActionListener ()
{
public void actionPerformed (ActionEvent e)
{
funExit ();
}
});
//***************************************************
//名称:funExit
//功能:退出确定函数
//输入:
//输出:
//返回:
//***************************************************
private void funExit ()
{
try
{
if (JOptionPane.showConfirmDialog (this, "确定要退出系统吗?", "信息", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
{
System.exit (0);
}
}
catch (Exception e)
{
System.exit (0);
System.out.println (e.getMessage ());
}
}
试试。。
public void shellClosed(ShellEvent e){
e.doit = false;
}
});
普通的Frame建立后“x”是需要自己添加功能的!
this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);然后截取关闭事件: this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e)
{ }});