Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How do you get the text field value from another java file

 
bobby, morkos
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a Demo.java which contains a text field value and I want to get it from ProcessListeener.java. Could anyone help?
 
Michael Szul
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You would just have to pass the value to the other program:
public class Demo {
String value = "";
Listener.getThisText(value);
}
public class Listener {
public void getThisText(String value) {
}
}
Is something like this what you are referring to? You post wasn't very specific.
This is just one of several ways that you can pass information back and forth between classes.
 
bobby, morkos
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I cant because I have a class Listener. Is there a way, without writing to a file or xml and then retrieving it later.
class JTableButtonMouseListener implements MouseListener {
}
 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bobby,
All Events have a source associated with them, so just use it. For example, the following code listens to a textfield action event:

If you need some other object then the one sent then you will need to write accessors from the creating class and then call them from your listener class. You will also need to pass in a reference to the creating class (usually done through the constructor). For example:
tf.addActionListener( new Listener( this ) );
Regards,
Manfred.
 
bobby, morkos
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What if the text value changes all the time. Is there a way to listeen for a modification in the text field and change it accordingly. Thanks for your help.

Originally posted by Manfred Leonhardt:
Hi Bobby,
All Events have a source associated with them, so just use it. For example, the following code listens to a textfield action event:

If you need some other object then the one sent then you will need to write accessors from the creating class and then call them from your listener class. You will also need to pass in a reference to the creating class (usually done through the constructor). For example:
tf.addActionListener( new Listener( this ) );
Regards,
Manfred.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic