• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

It doesnt see my 'if' statements

 
W. Schaible
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if (btn == "+")

try it like this

if (btn.equals("+"))

same for the other one
 
Sumit Patil
Ranch Hand
Posts: 296
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
fred rosenberger
lowercase baba
Bartender
Posts: 12196
35
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.


 
W. Schaible
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is a test. Your method removed indentation and removed context highlighting. Your method does the opposite of what you say.




}[/code][/code][/code]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic