• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Length Converter Calc

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm having trouble with some code I'm building a length converter that converts length from 5 text fields if the user enters a value in one text field for say millimeter, then meters, yards, feet and inches should be filled out when the convert button is clicked. I wrote 5 if statements that get text from the field if the field has text in it then it should execute the code. The problem is it doesn't follow these statements it just runs through all the if statements and tries to perform all the operations.
 
Marshal
Posts: 79977
397
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't use == or != for objects, which includes Strings. Use the equals method.
 
Vinay Berry
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how can i implement that into the code?
 
Rancher
Posts: 600
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Vinay Berry wrote:how can i implement that into the code?



Instead of something like this:

You would do this:


John.
 
Vinay Berry
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks it works now!
 
Sheriff
Posts: 22815
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To check for empty Strings you can also use !MField.getText().length() == 0.
 
Vinay Berry
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Prime wrote:To check for empty Strings you can also use !MField.getText().length() == 0.



haha we just learned about that method too it probably would've impressed the professor if I used it in my code
 
Campbell Ritchie
Marshal
Posts: 79977
397
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should be looking through the API documentation anyway, so you ought to have found that method.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Vinay Berry wrote:I'm having trouble with some code I'm building a length converter that converts length from 5 text fields if the user enters a value in one text field for say millimeter, then meters, yards, feet and inches should be filled out when the convert button is clicked. I wrote 5 if statements that get text from the field if the field has text in it then it should execute the code. The problem is it doesn't follow these statements it just runs through all the if statements and tries to perform all the operations.


Thanks you for the post.
Hi guys, Im a newbie. Nice to join this forum.
__________________
Movies Online Free

 
Campbell Ritchie
Marshal
Posts: 79977
397
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
. . . and welcome to JavaRanch ( ), Sharon nguyen
 
Oh sure, it's a tiny ad, but under the right circumstances, it gets bigger.
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic