Dear friends,

I don't know, I cannot seem to figure this out, should i use arrays,,,or
what? Here is my problem, the user is allowed to press the button as many
times as they want, and I have to tally up the amounts.

My code is wild I know,, learning, and probablly going about it the wrong

But it is the only way I know how to make it work,

Perhaps you can help me, please see my code:

class ButtonHandler implements ActionListener {

// moved to global scope and not block scope.

int num1, num2, num3, num4, total;

public int addMoney(){

total = num1 + num2 + num3 + num4;

return (total);


public void actionPerformed(ActionEvent evt) {

if (evt.getSource() == bttnItem1) {

System.out.println("\nUser has chosen Chocolate.");
infoMessage.setText("User chosen Chocolate.");

} else if (evt.getSource() == bttnItem2) {

System.out.println("\nUser has chosen Peanuts.");
infoMessage.setText("User chosen Peanuts.");

} else if (evt.getSource() == bttnItem3) {

System.out.println("\nUser has chosen Candy.");
infoMessage.setText("User chosen Candy.");

} else if (evt.getSource() == bttnItem4) {

System.out.println("\nUser has chosen Soda Pop.");
infoMessage.setText("User chosen Soda Pop.");

} else if (evt.getSource() == bttnFive) {

System.out.println("\nUser has added 5 cents.");
num1 = 5;

} else if (evt.getSource() == bttnTen) {

System.out.println("\nUser has added 10 cents.");
num2 = 10;
I am just trying to add up the buttons clicked, how shall I go about this??

Any ideas would be greatly appreciated, as I am lost and need some advice,
professional pointers to how I should do this?

Please help?