• Post Reply Bookmark Topic Watch Topic
  • New Topic

JtextField Issue

 
Sandeep DSouza
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a textfield "txtclientID".... and have a variable clientID which is of type "int" so how do I assign the value that I enter into the textfield to the variable of type int.
for example: In the case strings its simple
string variable = textfield.getText();
how do I do this with integers.
can someone help me with this.. Please
thanks,
sandeep
 
Prashanth Bhanu
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sandeep,
U can assign the txtField value to a integer variable by doing the following
int value = Integer.parseInt(txtFild.getText().trim());
this sholud help u.
bye
 
Mohsen Gamshad
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi Sandeep,
U can assign the txtField value to a integer variable by doing the following
int value = Integer.parseInt(txtFild.getText().trim());
this sholud help u.
bye

and while you're at it make sure you enclose it in a try/catch block. At least the NumberFormatException exception should be handled just in case your user types something other than a number.
Mohsen
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!