• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

parsing from JTextField to double

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:


 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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")).
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic