File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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: 19696
    
  20

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
How To Ask Questions How To Answer Questions
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2183
    
    7


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.
 
wood burning stoves
 
subject: parsing from JTextField to double