Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

getText from the textField

 
Bin Wu
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I hava a question about the TextField as follows, should be relative to String accurately.
String typedString = textField.getText();
How can I to transfer the typedString to primitive int? I must code myself or can get the result through the java library directly? Thanks in advance.
 
Paul Smiley
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry to say this, but you must parse it yourself...
 
Andrew Spruce
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As the value may be a non-numeric character it is sensible to do this anyway,
I think there are static methods of the Number classes like Interger.parseInt(String s) or Double.parseDouble(String s) that throw a number format exception if the string evaluates to number that is out of range or is not a number at all.
Hope this helps.
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!