• 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

Reading input from jTextField and passing it to another class

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am having trouble taking user input and passing it to another class as a variable. If I assign the value explicitly (see line 59), it works just fine. What I want to do though, is assign the input from inputField to the variable inputVariable. I tried using:

inputVariable = inputField.getText();

This does not work. Regardless of what is typed into inputField, the
output I get is just:

"The user typed "

Any help would be greatly appreciated.


 
Bartender
Posts: 322
24
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Warren,

Welcome to the Ranch!

Looks like you have a great start there, and thank you so much for using code tags - that makes it much easier for everyone to read and help you.
Now, think through the flow of your collectInput() method, and in particular when is the inputField.getText() statement being run? Is it after the "Submit" has been pressed?
No, it's part of the collectInput() method run. The call is being made, it is just that the inputField is still set to be empty at that time.

You will want to think about where the getText call should be in order to retrieve data after the Action has been Performed.
You may also want to check out the Java Tutorial on Text Fields, as the TextDemo.java file there gives you a good idea on how to accomplish this if you are not sure.

Cheers!
Chris
 
Warren Silva
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you, Chris! I was able to get this working with the information in the tutorial.
 
Chris Barrett
Bartender
Posts: 322
24
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome - happy I could help clarify that point and good luck on your Java development!

Cheers!
 
They weren't very bright, but they were very, very big. Ad contrast:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic