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

后端 未结 5 423
没有蜡笔的小新
没有蜡笔的小新 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:54

    You can use getter and setter methods...

    Set the username in a setter. And using object of login.java use it in account.java through getter...

    public class login {
        private String username;
        private String password;
    
        public String getUsername() {
            return username;
        }
        public void setUsername(String username) {
            this.username = this.usernameTextField.getText();
        }
        public String getPassword() {
            return password;
        }
        public void setPassword(String password) {
            this.password = this.passwordTextField.getText();
        }
    }
    

    Using objects of login.java access getPassword(), getUsername() in account.java. you need to pass object of login.java to account.java first...

提交回复
热议问题