重新打开之前关闭的 Window Java

Reopen previously closed Window Java

我开发了一个程序来学习登录的工作原理。我有一个 window(jFrame),您可以在其中使用“创建新帐户”按钮登录。如果单击此按钮,登录 window 将关闭并创建帐户。 window(另一个文件)打开。我希望它在您创建帐户后重新打开登录 window。

我的问题:


我不知道如何重新打开登录window。是重启mainmethod还是别的什么,希望你们能告诉我。

第一个window


public class password extends javax.swing.JFrame {

    public password() {
        initComponents();
    }
     private void initComponents() {

        jButton1 = new javax.swing.JButton();
        [some more Elements...]

        jButton1.setText("Create an account");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        [more layoutstuff...]
      }
     //event where it opens the new window and closes the login window  
     private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        register reg = new register();
        reg.register();
        dispose();
    }
    
    public static void main(String args[]) {

        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(password.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(password.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(password.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(password.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }

        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new password().setVisible(true);
            }
        });
    }
     // Variables declaration - do not modify                     
        private javax.swing.JButton jButton1;
      [more elements...]
}

秒window

public class register extends javax.swing.JFrame {

    public register() {
        initComponents();
    }
    private void initComponents() {

        jTextField1 = new javax.swing.JTextField();
        [again more elements and layoutstuff...]
    }
   public static void register() {

        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new register().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify                     
    private javax.swing.JButton jButton1;
    [more elements]
}

请原谅我的问题,但我对编程还很陌生。

您可以隐藏然后稍后显示登录 window 或者您可以汇总一个新的登录 window。