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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using actionlistener with an array of jbuttons

Status
Not open for further replies.

Ravana

Programmer
May 25, 2003
1
AU
i have a 3,3 array of jbuttons with actionlisteners attached.


how can i use actionperformed to pick out the one that was pressed and change it's name?

i treid using the getSource but i need to get the two numbers for the button position
 

This is the only way to do it:
an ActionEvent only contains the address of the JButton that is pressed. You'll have to search your buttonarray for a matching address.

public void actionPerformed(Actionevent e) {
if (e.getSource()==buttons[0][0]) // .....
if (e.getSource()==buttons[0][1]) // .....
if (e.getSource()==buttons[0][2]) // .....
if (e.getSource()==buttons[1][0]) // .....
// .......
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top