I used Java graphics to create a 500 x 500 Checkers board within a JPanel, which was placed within a JFrame. To make the pieces, I wrote a series of for loops to create JButtons across the board. The following for loops correctly set up the pieces for one side of the board:
for(int x = 355; x>=55;x-=100)
{
Piece p = new Piece();
p.addActionListener(new ButtonListener());
p.setBounds(x,5,40,40);
b.add(p);
}
for(int x = 5;x<=355; x+=100)
{
Piece p = new Piece();
p.addActionListener(new ButtonListener());
p.setBounds(x,55,40,40);
b.add(p);
}
for(int x = 355; x>=55;x-=100)
{
Piece p = new Piece();
p.addActionListener(new ButtonListener());
p.setBounds(x,105,40,40);
b.add(p);
}
However, I just started setting up the pieces for the other side of the board with this for loop, and none of the buttons are being displayed:
for(int x = 5; x>=355;x+=100)
{
Piece p = new Piece();
p.addActionListener(new ButtonListener());
p.setBounds(x,255,40,40);
b.add(p);
}
Why is this happening?