Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting actionlisteners to arrays and setting contentpanes to arrays

Status
Not open for further replies.

happyb

Programmer
Oct 25, 2000
29
AU
Hi

Does anyone know how to give add an ActionListener to an array? If I were to add it to a a button I go...

JButton button = new JButton;
c = getContentPane();
c.add(button)
button.addActionListener(Listener);

But... how do I add an array ... buttons[]... to the above.

When I use

c.add(buttons) or
c.add(buttons[])

it does not work... and when I use

buttons[].addActionListener it does not work.

Any help would be great,

Thanks,
HappyB :)
 
I think you can only do it with cycle.

for (int i=0; i<buttons.length; i++) {
buttons.addActionListener(Listener);
}

Bye, Otto.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top