import java.awt.*; import javax.swing.*; import java.util.*; public class boardPanel extends JPanel { static final boolean USEVEC = true; // multiple painting per square (assume user paints each default) int xdim, ydim; int wdim, hdim,sqw, sqh; final Color background = Color.white; boardObject[][] board; // objects on board, listed as array of boardObject elements Vector boardVec; // objects on board to paint, listed as vector in order of painting boardObject def; Dimension preferredSize; // d is a boardObject for the background. public boardPanel(boardObject d, int x, int y) { this(d,1,1,x,y); } public boardPanel(boardObject d, int x, int y, int w, int h) { //bObjects = b; def = d; xdim = x; ydim = y; wdim = w; hdim = h; sqw = wdim / xdim; sqh = hdim / ydim; //System.out.println("sqx:"+sqw+" sqy:"+sqh); preferredSize = new Dimension(wdim, hdim); board = new boardObject[xdim][ydim]; boardVec = new Vector(); // this instance will probably get replaced, // but allows setting before clearing } public boolean setSquare(boardObject b, Dimension d) { return setSquare(b,d.width, d.height); } public boolean setSquare(boardObject b, int x, int y) { if ((x<0) || (x>=xdim) || (y<0) || (y>=ydim)) return false; //out of range if (USEVEC) { boardContainer thisSquare = new boardContainer(new Dimension(x,y),b); boardVec.addElement(thisSquare); } else board[x][y] = b; return true; } public void clearBoard() { if (USEVEC) boardVec = new Vector(); else { for (int i=0; i=xdim) || (y<0) || (y>ydim)) return false; //out of range board[x][y] = null; return true; } public void paintComponent(Graphics g) { //super.paintComponent(g); drawboard(g); } public Dimension getPreferredSize() { return preferredSize; } public Dimension getMaximumSize() { return preferredSize; } public Dimension getMinimumSize() { return preferredSize; } void drawboard(Graphics g) { g.setColor(Color.black); g.fillRect(0,0,getWidth(), getHeight()); sqw = getWidth()/xdim; sqh = getHeight()/ydim; // draw background panels if (def != null) { for (int y=0; y