Java:如何在打开另一个JFrame时关闭当前的JFrame?

5

我的程序以JFrame中带有文本字段的图片开始。当用户输入"start"时,我希望它关闭图片JFrame并打开另一个包含主程序的JFrame。我尝试在图片窗口中使用

processEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING));

但它会关闭所有窗口。

12个回答

-1

这是我想到的在关闭另一个JFrame时打开新JFrame的方法:

JFrame CreateAccountGUI = new JFrame();
CreateAccountGUI.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
CreateAccountGUI.setSize(800, 600);
CreateAccountGUI.setLocationRelativeTo(null);
CreateAccountGUI.setVisible(true);   
this.setVisible(false);

-1
if(username.equals("gaffar")&&password.equals("12345"))
    {
    label.setText("Be ready to continue");
    //Start of 2nd jframe
    NewJFrame1 n=new NewJFrame1();
     n.setVisible(true);
     //Stop code for ist jframe
     NewJFrame m=new NewJFrame();
     m.setVisible(false);
     dispose();
    }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接