As the title says, I need to replace part of the name of the variable with the number of for loop iterations.
In my code, the variables are a grid of buttons on Swing, going from a1 to c3. I have to re-color all of the buttons dependent on the p1grid[] array. I cannot (to my knowledge) put them in an array of their own since they are buttons. Here's my code:
for (int i = 1; i < 4; i++) {
if (p1grid[i - 1].equals("empty"))
("a" + i).setBackground(Color.LIGHT_GRAY);
else
("a" + i).setBackground(Color.RED);
}