addActionListener / actionPerformed

Discussion in 'Java' started by nick yakman, Apr 15, 2004.

  1. nick yakman

    nick yakman Guest

    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


    ---
    Outgoing mail is certified Virus Free.
    Checked by AVG anti-virus system (http://www.grisoft.com).
    Version: 6.0.657 / Virus Database: 422 - Release Date: 13/04/04
    nick yakman, Apr 15, 2004
    #1
    1. Advertising

  2. You an inner class!

    "nick yakman" <> wrote in message
    news:B9kfc.30$...
    > 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
    >
    >
    > ---
    > Outgoing mail is certified Virus Free.
    > Checked by AVG anti-virus system (http://www.grisoft.com).
    > Version: 6.0.657 / Virus Database: 422 - Release Date: 13/04/04
    >
    >
    Justin Fowler, Apr 15, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marcello
    Replies:
    0
    Views:
    390
    Marcello
    Oct 2, 2003
  2. -

    actionPerformed(null)

    -, Mar 27, 2005, in forum: Java
    Replies:
    0
    Views:
    433
  3. Asanka
    Replies:
    3
    Views:
    3,686
    Asanka
    Oct 10, 2006
Loading...

Share This Page