I'm writing a program and I've run into an issue...
I create 1 JLabel array and 1 JButton array. The JLabel array holds a string, a Club Name. The JButton array holds a string that just says "Edit".
A For loop then fills each array based on the length of the clubs array, as well as add an action listener for each button.
When the user clicks the JButton corresponding to the JLabel it initiates an Event. In this event I need to find out the value stored in the JLabel that matches the JButton.
Since the event listener doesn't know it's inside a loop, I can't use it.
How do I achieve the goal I want?
See the bellow code.
JLabel clubs[] = new JLabel[99];
JButton editAClub[] = new JButton[99];
for(int i=0; i <= (allClubs.length - 1);i++)
{
clubs[i] = new JLabel("Club " + i);
editAClub[i] = new JButton("Edit");
editAClub[i].addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
selectedClub = clubs[i].getText().toString();
System.out.println(selectedClub);
}
});
}