如何在Netbeans中将变量值从一个JFrame传递到另一个JFrame [英] How to pass a variable value from one JFrame to Another JFrame in Netbeans
问题描述
我有两个JFrames login.java
和account.java
我需要从login.java
页面获取username
并将其放在account.java
JFrame
中的变量中.如何在Java NetBeans中使用Swing做到这一点?
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 variable in the account.java
JFrame
. How can I do this in the Java NetBeans using the Swing?
推荐答案
您可以使用getter和setter方法...
You can use getter and setter methods...
在设置器中设置用户名.并使用login.java对象通过getter在account.java中使用它.
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();
}
}
使用login.java对象访问account.java中的getPassword()
,getUsername()
.
您需要先将login.java对象传递给account.java ...
Using objects of login.java access getPassword()
, getUsername()
in account.java.
you need to pass object of login.java to account.java first...
这篇关于如何在Netbeans中将变量值从一个JFrame传递到另一个JFrame的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!