Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
377 views
in Technique[技术] by (71.8m points)

jframe - Reopen previously closed Window Java

I developed a program to learn how log-in works. I've got a window(jFrame) where you can login with a button on it "create new account". If you click this butten, the login window closes and the create acc. window(another file) opens up. I want it to reopen the login window after you've created your acc.

My Problem:


I don't know how to reopen the login window. Be it by restarting the mainmethod or somethingelse, which you guys can tell me hopefully .

First 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...]
}

second 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]
}

Please excuse me for my question but I am very new to programming.

question from:https://stackoverflow.com/questions/65924048/reopen-previously-closed-window-java

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...