简体   繁体   English

如何破坏前一帧打开一个新的框架

[英]How to destroy the previous frame open opening a new frame

I am building an application in java that has 2 JFrames. 我正在java中构建一个具有2个JFrame的应用程序。 1st frame has a button that upon clicking should open the next JFrame while the previous one should close. 第一帧有一个按钮,点击后应该打开下一个JFrame而前一个JFrame应该关闭。 I know how to display the next frame but: How do I close the previous JFrame automatically when the next JFrame opens ? 我知道如何显示下一帧但是: 如何在下一个JFrame打开时自动关闭以前的JFrame?

I tried thie following code: 我试过以下代码:

addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                new GUI();//next frame
                                this.dispose();//compile-time-error
            }

Where you call this.dispose() , the object referred by this is an instance of ActionListener . 在调用this.dispose()this引用的对象是ActionListener一个实例。 To invoke the instance of GUI type GUI.this.dispose() instead. 要调用GUI类型GUI.this.dispose()的实例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM