-
take value other form
I have a problem like this:
I have a form LogIn with 2 textfileds Username and Password
when i enter a correct username and password , application will hide a LogIn form and show form 2
What i want to ask is how to take a Username value that i just entered in form LogIn and and set to the TextField in form 2 like " Welcome (username value from Log In form)" ?
i tried:
Form LogIn:
public String user = UserName.getText();
Form 2:
LogIn log =new LogIn();
textfield.setText(log.user);
and that not work ! the textfield is blank...
Help me !!
-
by "Form" do you mean JFrame? Myself, I'd have a public method in the first class, the one responsible for handling your login GUI, something like so:
Code:
public String getUserName()
{
// assuming that this class has a private JTextField variable
// named userNameTextField
return userNameTextField.getText();
}
Then in the second class, when I wanted this data, I'd call this method on an instance of the first class (the instance that was displayed!).
-
oh thanks, i 'll try that, thanks for reply!
-
I already tried that, but did'nt work
LogIn Form:
private JTextField userName;
public String getUsername()
{
return userName.getText();
}
SecondForm:
LogIn log = new LogIn();
JTextField.setText(log.getUsername());
the text in the JtextField is blank T_T
-
Well, if you've just instantiated the Login class, the userName JTextField is blank, isn't it? And that's where you're getting the text that you're setting to....
Hey wait. setText isn't a static method, you can't invoke it on the class.
Hop across to the Sun site and find the Swing tutorial. You need it badly.
db