Forums Register Login

Calculator clear button not working...

+Pie Number of slices to send: Send
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).]
+Pie Number of slices to send: Send
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).]
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
If you typed the - sign followed by the = with no other numbers typed, an exception was thrown. It tried to parse the - as a number.
I need a new interior decorator. This tiny ad just painted every room in my house purple.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 6701 times.
Similar Threads
This Keyword
divide by 0 exception
pls help adding menu bar to prgram
NullPointerException - Using JTextField to Add Numbers
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 04:56:48.