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

Remeber which label in array was clicked?

Status
Not open for further replies.

adamr99

Programmer
Jun 25, 2001
59
0
0
US
I have an array of LABELS. I also have a mouselistener and I need to know how to remember which label was clicked and change the background icon for it.

any ideas????


Thanks

Adam
 
One method would be to use a JButton's, with no borders and attach a listener to each.
 
Can you show me how to do an array of labels (or jlabels)? You've just givven me an idea, thanks.
 
This is one way to do it although probably not the most efficient.

In a for loop add an actionListener to each label in your array. Create a final int variable to track the index number of your array. In the mouse_clicked method use both the index int and the ActionEvent e as parameters

for(int i=0;i,array.length;i++){
final int index = i;
array.addMouseListener(Listener type){
array_Mouse_Clicked(index, e)etc....

Set up your array_Mouse_Clicked method like...

public void array_Mouse_Clicked(int index, ActionEvent e){
Actions to be performed;
}

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top