This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
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 Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "parsing from JTextField to double" Watch "parsing from JTextField to double" New topic
Author

parsing from JTextField to double

Bart Simpsong
Greenhorn

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
Sheriff

Joined: Oct 27, 2005
Posts: 20080
    
  30

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


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2373
    
    8


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’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: parsing from JTextField to double
 
It's not a secret anymore!