wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes It doesnt see my 'if' statements Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "It doesnt see my Watch "It doesnt see my New topic
Author

It doesnt see my 'if' statements

W. Schaible
Greenhorn

Joined: May 09, 2012
Posts: 5
A stripped down version of my program is in the 2 files copied below. It is a simple calculator like in Windows accessories. The example below only does addition and subtraction however it doesn't work. Here's how it is supposed to work. A number is sent to the textbox using button clicks and when '+' button is clicked the displayed string is converted to double. The displayed string remains displayed until the first digit of the next number is entered then the first number is cleared and the second number begins in the display. When '=' is clicked the second displayed number (actually a string) is converted to double and added to the first double number. The operation should be controlled by the 'opFlag' and 'addFlag' settings. The problem apparently is that the 'if' statements that set the flags are not being executed. I tried NetBeans debugger to watch the values but I don't know how to use the debugger well enough. I'm hoping someone here can tell me what I'm doing wrong so I can move on. Your comments will be appreciated. TIA Bill S.

THE GUI FILE:



THE CALCULATION FILE:




[Added code tags - see UseCodeTags]
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
if (btn == "+")

try it like this

if (btn.equals("+"))

same for the other one
Sumit Patil
Ranch Hand

Joined: May 25, 2009
Posts: 296

I tried NetBeans debugger to watch the values but I don't know how to use the debugger well enough.

You can always use System.out.println() to see the values...


Thanks & Regards, Sumeet
SCJP 1.4, SCWCD 5, LinkedIn Profile
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11152
    
  16

W. Schaible,

I copied part of your code, and re-posted it here using "code tags". as you can see, it is formatted much better, is context-highlighted, and is much more readable. Please start using these in the future. You can simply highlight your source and click the button labeled "code" above where you enter your text.

Thanks.




There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
W. Schaible
Greenhorn

Joined: May 09, 2012
Posts: 5
this is a test. Your method removed indentation and removed context highlighting. Your method does the opposite of what you say.




}[/code][/code][/code]
 
 
subject: It doesnt see my 'if' statements
 
Similar Threads
Very Very New
help with actionPerformed method.
Text area
GUI
what i have done