【发布时间】:2017-04-11 04:40:52
【问题描述】:
我试图从另一个类 ABC 中显示一个名为 testView 的类的窗口。窗口包含一个按钮。我想在单击该按钮时关闭窗口。我怎样才能关闭它?
public class testView extends JFrame {
protected JButton closeButton = new JButton("Close");
testView(){
this.setSize(1000,700);
this.setTitle("Test");
Container window = getContentPane();
window.setLayout(new FlowLayout());
this.setResizable(false);
window.add(closeButton);
}
}
public class ABC{
public static void main(String[] args) {
testView View = new testView();
View.setVisible(true);
}
}
从另一个类 ABC 显示窗口。如何在按钮单击时关闭窗口?
【问题讨论】:
-
只需使用 Dispose() 方法关闭它