• 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 I get text from a java text field?

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check Integer class.

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

Hope this helps.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 2856
10
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
got it, was using a java text field and just used JavaTextField.getText() (lol)

thanks guys
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic