我试图从另一个类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显示。如何点击按钮关闭窗口?
答案 0 :(得分:1)
您可以这样做:
04-10 18:35:26.218 24522 24541 V AsyncTexUpload: id=102 glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 0, 1432, 2048, 96, GL_COMPRESSED_RGBA_ASTC_8x8, 49152, ptr)
04-10 18:35:26.218 24522 24541 V AsyncTexUpload: Logged message 8246, 824C, 7FFFFFFF, 9146, image size is invalid for compressed texture
04-10 18:35:26.218 24522 24541 V AsyncTexUpload: glCompressedTexSubImage2D error 1281
此代码添加了一个按钮动作侦听器,然后当该按钮有一个对其起作用的动作时,它会告诉帧关闭。希望这会有所帮助:)
答案 1 :(得分:0)
要使窗口不可见,您必须调用
java.awt.Window.setVisible(false)
但是使用dispose
方法可以从内存中删除窗口。