addActionListener / actionPerformed

N

nick yakman

I have 2 groups of buttons in an applet. One set of buttons to represents
money and the other set selects an item.

I have used:
money1p = new Button("1p");
money1p.addActionListener(this);
moneyKeyPanel.add(money1p);
money2p = new Button("2p");
money2p.addActionListener(this);
moneyKeyPanel.add(money2p);
ect for the money keys, with:

public void actionPerformed(ActionEvent ae)
{
String command = ae.getActionCommand();
int addedCredit = 0;

if(command.equals("1p"))
addedCredit = 1;
else if(command.equals("2p"))
addedCredit = 2;
else if(command.equals("5p"))
addedCredit = 5;
else if(command.equals("10p"))
addedCredit = 10;

ect..
totalCredit+= addedCredit;
}

This set of buttons works fine. But i cant set up a similar
"actionPerformed" Method for the second set of buttons.

Can they be added to the actionPerformed Method without interfering or how
can i set up a second actionPerformed method.

All help welcome
Many thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top