JAVA 关闭当前窗口

来源:百度知道 编辑:UC知道 时间:2024/05/30 01:11:48
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
zhujiemian a=new zhujiemian();
a.show();

}
});
怎么写能关闭当前窗口啊?
并且提示说不建议用Windows的方法show(),我应该怎么改

直接释放资源就关掉了:this.dispose();
show()方法过时了 用setVisible(true);

this.addWindowListener(new WindowAdapter(){//关闭窗口事件
public void windowClosing(WindowEvent e) {
System.exit(0);
}});

你只要在initialize()方法中加这样一句话

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

改用
a.setVisible(true);