🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #10815

Re: JButtonActionPerformed Listener

#10815
From: Marcel van den Dungen
Date: Thu, 05 Aug 1999 00:00
50 lines
1976 bytes
i'm not sure what exactly is your problem but i gues this will do it

ButtonTracker bTracker = new ButtonTrackerl();
Button[] buttons = new Button[96];

//in your init....
for (int i = 0; i < 96; i++)
{
    buttons[i] = new Button;
    //do your stuff
    buttons[i].setActionCommand("" + i);
    buttons[i].addActionListener(bTracker);
}

class ButtonTracker implements ActionListener
{
    public void actionPerformed(ActionEvent a)
    {
        //cast a.getActionCommand() to int, let's say actionInt
        switch (actionInt)
        case : 0 {//do your stuff}
        case : 1 {//do your stuff}
            ...
        case : 95 {//do your stuff}
    }
}

hoping to be helpful
greetings
casper


Musa S Marasi wrote:

> Hi, this is my situation.
> I am trying to create a list of 96 buttons.
> I have a Jlistpane upon which is a Jpanel.  Now, instead of creating and
> putting on the Jpanel the 96 JButtons I am doing this in the Jbinit
> using a forloop, thus they will be created as the program runs.
> My question is if it is possible to add ActionPerformedListeners to all
> of theseJButtons the same way.  So far I have not been able to
> dynamiclly create them as such and the alternate method seems extremely
> long, timeconsuming as well as redundant.
>
> Any help in this regard will be greatly Appreciated.
> Shabber Abbas
> Code Technology
>
> shabber@codetech.com
> www.codetech.com
Technical Details
Message-ID: <37A99C40.9159F102@c-content.nl>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <37A98E17.BDD153BD@codetech.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,3a4068f0d32aa964
X-Google-Attributes: gid111d45,public
From: Marcel van den Dungen <info@c-content.nl>
Subject: Re: JButtonActionPerformed Listener
Date: 1999/08/05
Message-ID: <37A99C40.9159F102@c-content.nl>
X-Deja-AN: 509190172
Content-Transfer-Encoding: 7bit
References: <37A98E17.BDD153BD@codetech.com>
Organization: C-CONTENT b.v.
Content-Type: text/plain; charset=us-ascii
Mime-Version: 1.0
Newsgroups: borland.public.jbuilder.java.swing