How to pass a variable value from one JFrame to Another JFrame in Netbeans

后端 未结 5 417
没有蜡笔的小新
没有蜡笔的小新 2020-12-19 10:18

I have two JFrames login.java and account.java
I need to get the username from the login.java page and put it in a v

5条回答
  •  北海茫月
    2020-12-19 10:49

    Since you have asked how to pass a variable value from one JFrame to Another JFrame (using swing). So for this put one textbox(tx) and a button(jButton3) in login.java and one label(lx) in account.java where we will print the value of the textbox from login.java .

    Type this in login.java :-

     private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                         
          String msg= tx.getText();
          new NewJFrame2(msg).setVisible(true);
        } 
    

    Then overload constructor in account.java :-

    public NewJFrame2(String abc ){
            initComponents();
            lx.setText(abc);
        }
    

提交回复
热议问题