File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

parsing from JTextField to double

 
Bart Simpsong
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, my program suppose to convert a number(pounds) into kilograms. Two JTextField and one Button. I am not sure how to parse the value from JTextField into double but this is what I have so far. Thank you for any help. This is not working, here is the error message:


 
Rob Spoor
Sheriff
Pie
Posts: 20388
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch! Can you please UseCodeTags next time? I've added them for you this time.

Now, to the problem.
The first line does not create a text field with contents "10" but a text field that will be large enough to show 10 characters. Its content is still empty (""). To get a JTextField to show the value "10" you must a) use textField.setText("10"), or b) create it using a String value (new JTextField("10")).
 
Rob Camick
Ranch Hand
Posts: 2475
8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


That code is in the wrong place. You want that code to be executed when the user does some action. So I guess that code and your conversion code should be added to your ActionListener. That is when the user is finished typing the number they want converted, they will click on a button to get the result.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic