// Board.java import java.awt.*; public class Board extends Panel { private static final int ROWSIZE = 3; private int COLSIZE; private ColorButton Life[][]; private Color color = new Color(22, 107, 29); private int x, y; public Board(Image image, int _colSize) { COLSIZE = _colSize; Life = new ColorButton[ROWSIZE][COLSIZE]; setLayout(new GridLayout(ROWSIZE, COLSIZE + 1, 1, 1)); for(int row = 0; row < ROWSIZE; row++) for(int col = -1; col < COLSIZE; col++) { if (row == ROWSIZE - 1) if (col == -1) add(new Label("")); else add(new Label("" + (COLSIZE - col - 1))); else if (col == -1) if (row == 0) add(new Label("X:")); else add(new Label("Y:")); else { Life[row][col] = new ColorButton(image, 2, color); Life[row][col].hasLife = false; add(Life[row][col]); } } } public void setCoords(int col1, int col2) { clear(); setX(col1); setY(col2); Life[0][COLSIZE - x - 1].hasLife = true; Life[1][COLSIZE - y - 1].hasLife = true; Life[0][COLSIZE - x - 1].repaint(); Life[1][COLSIZE - y - 1].repaint(); } public void setX(int _x) { x = _x; } public void setY(int _y) { y = _y; } public int getX() { return x; } public int getY() { return y; } public void setChangeable(boolean canChange) { for(int row = 0; row < ROWSIZE - 1; row++) for(int col = 0; col < COLSIZE; col++) Life[row][col].isChangeable(canChange); } public void clear() { for(int row = 0; row < ROWSIZE - 1; row++) for(int col = 0; col < COLSIZE; col++) if (Life[row][col].hasLife == true) { Life[row][col].hasLife = false; Life[row][col].repaint(); } } }