aspose file tools*
The moose likes Beginning Java and the fly likes How do I get text from a java text field? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How do I get text from a java text field?" Watch "How do I get text from a java text field?" New topic
Author

How do I get text from a java text field?

Zak Tacc
Greenhorn

Joined: Feb 01, 2010
Posts: 25
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

Joined: Jun 02, 2010
Posts: 52
Check Integer class.

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

Hope this helps.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42293
    
  64
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.


Ping & DNS - my free Android networking tools app
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

Just to add to what Ulf said above, have your input validated before parsing .


SCJP, SCWCD.
|Asking Good Questions|
Zak Tacc
Greenhorn

Joined: Feb 01, 2010
Posts: 25
got it, was using a java text field and just used JavaTextField.getText() (lol)

thanks guys
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: How do I get text from a java text field?