Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Retriving jTextfield value from an other java file

 
Tapan Prajapati
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
login.java

TxMgt.java


I want to retrive the value of JTextfield1 (usern) value in my second form TxMgt how can i retrive?
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you change the constructor so you can pass the data when TxMgt is created
//public TxMgt() {
to

String userName
public TxMgt(String un) {
userName = un;

and in Login.java
//TxMgt tx = new TxMgt();

to
TxMgt tx = new TxMgt(jTextField1.getText());
 
Tapan Prajapati
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael Dunn wrote:you change the constructor so you can pass the data when TxMgt is created
//public TxMgt() {
to

String userName
public TxMgt(String un) {
userName = un;

and in Login.java
//TxMgt tx = new TxMgt();

to
TxMgt tx = new TxMgt(jTextField1.getText());


This is for only one text field , but if in case i want to use multiple textfields of my first form into second form then? is there any other way?
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
create a textfield array and pass the array
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic