I am currently coding a game board (using Java Swing). I wrote the following to display the board (rows go from A-I, and columns go from 1-12):
JPanel panel = new JPanel(new GridLayout(9,12,5,5));
panel.setBounds(10, 11, 800, 600);
frame.getContentPane().add(panel);
//board
for(int r = 0; r<9; r++)
{
for(int c = 0; c<12; c++)
{
panel.add(new JButton((c+1) + numberList[r])).setBackground(Color.WHITE);
}
}
The user is supposed to be able to buy certain slots on the board. For example, if User A buys A1 then that button, on the board, is supposed to turn RED and if User B buys A2 then that button is supposed to turn GREEN (User will have certain buttons that have the available tile coordinates and after the button is clicked, the tiles on the board are supposed to change color and stay). Since I created all the buttons in a loop and I didn't name each of them, can I still accomplish this? I don't want to create 108 buttons one by one.
I know I shouldn't have used buttons for the board, I am going to change it soon. I am going to use Graphics G
to use rectangles. However, I want to figure out my plan first.