I'm building a project for school and I want to make three money buttons (quarter, nickel and dime) that accumulates their value with every click of the button. When I'm done the text displayed will be grabbed and reParsed back to a double. I have that part done, I'm just drawing a blank on using a button accumulator.
double quarter = 0.0;
if (event.getSource() == quarterButton)
{
Possible loop???
quarter += .25;
}
String quarter2 = Double.toString(quarter);
amountDeposited.setText(quarter2);
It doesn't work... It just prints .25 and stops. I need it to accumulate each time the button is pressed. I can change the double to anything really that was just what I had in there now...
I suspect your issue is that your quarter
variable is declared inside the method you are showing. If so then it will be reset to 0 at each click. It needs to be declared at the class level so that it maintains its value between button clicks.