If someone could help me figure out how to get the clear button to work on my calculator, I would appreciate it. Instructions: Write a program that displays a calculator. It has 1. an input field at the top to enter a number (20 characters wide). 2. display field that displays the current total (20 characters wide not editable text field). 3. 3 buttons "Add", "Subtract", "Clear". 4. Title of "Calculator". . Calculator.java
This program works except for the clear button doesn't clear the field. Thanks for any help. ------------------ Thanks, Dianne
(Marilyn added code tags) [This message has been edited by Marilyn deQueiroz (edited October 28, 2001).]
You never call it once the = is pressed. When you perform calculate the start boolean is set to true. You didn't put in the - sign so it just sets lastCommand to command. ps try the - sign first before any numbers pressed then hit =. [This message has been edited by Paul Stevens (edited October 29, 2001).]
If I did what you said correctly, here are my results.
It all compiles and looks great, but the clear button still does not clear the results field. Did I correct it the right way? ------------------ Thanks, Dianne
Hi Dianne, It has something to do with your 'start' variable. Inside your actionPerformed method you are using : if( start ) { } else if( "Clear" ) { } Your start variable is always set so you never get to the else part. I don't have enough time to figure out what start is supposed to be ... Regards, Manfred.
if clear do the clear processing else you do what ever The start variable is messing your clear processing up. Did you try entering the - sign before anything else then the = sign?
Just wanted to say thanks. My problem that I turned still did not work all the way, but it was really close. Paul I just wasn't understanding what you meant about the - and = comments. So, if you could elaborate on that I would appreciate it. Thanks everyone again. ------------------ Thanks, Dianne