Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Get data from jtext field

 
Travis Gn
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to get an int from a JTextField, and read it into a method. I am unsure the syntax of it. Would it be something like:


also, how it the event handled from a JTextField? i'e' onfocus, onBlur... is there a way to change this? Thanks for you help.
 
Joe Ess
Bartender
Posts: 9339
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Originally posted by Travis Gn:

also, how it the event handled from a JTextField? i'e' onfocus, onBlur... is there a way to change this? Thanks for you help.

What is this event you speak of? You can register for FocusEvents, which would occur when someone leaves the field. You can register for KeyEvents, which would happen whenever someone hits a key. It is more common to have a button ("ok" or "submit") for the user to press when they are done filling in data. Register for the button's ActionEvent and read the field when you get it.
 
Travis Gn
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks; I am having a problem now with my paramaters and data types. My method is:


tower is tower(int, int, int, int).

because java.lang.String is a String, how can I convert it to an int?
 
Joe Ess
Bartender
Posts: 9339
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Integer.parseInt(someString);
 
Travis Gn
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Joe, sorry for the beginner questions.
 
barron logan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yea it would be:
tower(Integer.parseInt(input.getText()),3,2,1);
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic