aspose file tools*
The moose likes Beginning Java and the fly likes Length Converter Calc Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Length Converter Calc" Watch "Length Converter Calc" New topic
Author

Length Converter Calc

Vinay Berry
Greenhorn

Joined: Dec 04, 2009
Posts: 5
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.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38881
    
  23
Don't use == or != for objects, which includes Strings. Use the equals method.
Vinay Berry
Greenhorn

Joined: Dec 04, 2009
Posts: 5
how can i implement that into the code?
John de Michele
Rancher

Joined: Mar 09, 2009
Posts: 600
Vinay Berry wrote:how can i implement that into the code?


Instead of something like this:

You would do this:


John.
Vinay Berry
Greenhorn

Joined: Dec 04, 2009
Posts: 5
Thanks it works now!
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19696
    
  20

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


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Vinay Berry
Greenhorn

Joined: Dec 04, 2009
Posts: 5
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
Sheriff

Joined: Oct 13, 2005
Posts: 38881
    
  23
You should be looking through the API documentation anyway, so you ought to have found that method.
Sharon nguyen
Greenhorn

Joined: Dec 31, 2009
Posts: 1
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
Sheriff

Joined: Oct 13, 2005
Posts: 38881
    
  23
. . . and welcome to JavaRanch ( ), Sharon nguyen
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Length Converter Calc