I am trying to figure out how to refer to buttons generated from a nested for-loop. I am trying to assign a value to each button which can interact with a switch in an action listener. Would the buttons already have referencable names/IDs in my code, given as follows? Should I instead assign variables to each button? How might I do that? I am a beginner, btw.
for (int row = 0; row < rows; row++)
{
for (int column = 0; column < columns; column++)
{
JButton button = new JButton();
buttonPanel.add(button);
button.addActionListener(new coolActionListener());
}
}