wood burning stoves
The moose likes Swing / AWT / SWT and the fly likes parsing from JTextField to double Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "parsing from JTextField to double" Watch "parsing from JTextField to double" New topic

parsing from JTextField to double

Bart Simpsong

Joined: Mar 29, 2011
Posts: 1
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

Joined: Oct 27, 2005
Posts: 20202

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")).

How To Ask Questions How To Answer Questions
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2419

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
subject: parsing from JTextField to double
jQuery in Action, 3rd edition