Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

number from jTextField

Status
Not open for further replies.

Stevoie

Programmer
Jun 7, 2001
68
IE
Does anyone know how to get a number (int or float) from a JTextfield, when i get back a String, I have no way of converting it to a number.

Example: someone enters there age into the textfield, i need to know how to store this in a int,
Thanks in Advance
StevoIE
 
Text fields store text...period!! There is no such thing as a 'number field'.

"when i get back a String, I have no way of converting it to a number"

Sure you do:

try {
int i = Integer.parseInt(textfield.getText());
} catch (NumberFormatException nfe) {
// user didn't enter a valid number
}


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top