Hey.
I have been trying to do a drafts board, but i am having major problems with adding the pieces. Heres my Board. Any Suggestions??
import java.awt.*;
import javax.swing.*;
public class Board
{
protected JPanel[][] squares;
protected JFrame boardFrame;
protected Container container;
public void paint (Graphics g) { }
public Board()
{
boardFrame = new JFrame("MyDraughts");
container = boardFrame.getContentPane();
container.setLayout(new GridLayout(8,8));
create_squares();
boardFrame.setSize(400,450);
boardFrame.setVisible(true);
}
private void create_squares()
{
squares = new JPanel[8][8];
for(int i=0;i<8;i++)
{
for(int j=0;j<8;j++)
{
JPanel p = new JPanel();
p.setBackground(setColor(i,j));
squares[i][j]=p;
container.add(p);
}
}
}
private Color setColor(int x, int y)
{
if((x+y)%2 == 0)
return Color.WHITE;
else
return Color.BLACK;
}
}