• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 {
}
 
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Bring out your dead! Or a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic