Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How do I get text from a java text field?

 
Zak Tacc
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys I need help getting text from a field. I have a text field, and some number X has been entered into it. How do I capture that number and turn it into an int value? thanks

(i plan on taking that number and adding it to an array)
 
Manjusha Muraleedas
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check Integer class.

A parseInt method is there . You can make use of that function.

Hope this helps.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you talking about a javax.swing.JTextField? if so, check its javadocs - do you see any method that could be used to get its text?

As to turning text into a number, have a look at the javadocs of the java.lang.Integer class - it has methods to parse a String.
 
Amit Ghorpade
Bartender
Posts: 2854
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to add to what Ulf said above, have your input validated before parsing .
 
Zak Tacc
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
got it, was using a java text field and just used JavaTextField.getText() (lol)

thanks guys
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Zak Tacc wrote:got it, was using a java text field and just used JavaTextField.getText() (lol)


If you are going to continue to pursue programming, you'll want to be more precise in your communication. For instance, there is no such animal as a java text field -- just doesn't exist. There are Swing JTextFields, there are AWT TextFields, there a SWT equivalents, but none are the same. This may seem trivial to you, but again, if you're serious about this, you'll find out that it's anything but trivial.

Luck.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic