0
how to get String in jFrame and pass to another jFrame?
I have two jFrame (LoginForm, MainForm), LoginForm have a TextField (tfusername), how can get tfusername.gettext() in MainForm?
6 Antworten
+ 2
What returns null? And can you post the whole code?
+ 1
Whoops, guess I misunderstood what you were asking. You can pass the text variable via an instance method of the Jframe you are passing it to.
+ 1
a simple way:
in loginform>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
public class LoginForm extends javax.swing.JFrame{
public static String Username;
public static String Password;
//create a method
public void InsertData(){
Username = tfusername.gettext();
Password = tfpassword.gettext();
}
in MainForm>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
String user = UserName;
String Pass = Password;
0
You can just use the getText() method of the JTextField class.
String text = tfusername.getText();
https://docs.oracle.com/javase/7/docs/api/javax/swing/JTextField.html
Note that it is inherited from JTextComponent
https://docs.oracle.com/javase/7/docs/api/javax/swing/text/JTextComponent.html
0
return null