• Post Reply Bookmark Topic Watch Topic
  • New Topic

Reading input from jTextField and passing it to another class  RSS feed

 
Warren Silva
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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.


 
Chris Barrett
Bartender
Posts: 321
24
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • 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
  • 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: 321
24
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome - happy I could help clarify that point and good luck on your Java development!

Cheers!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!