/* * File: Checkerboard.java *------------------------ * This program draws a checkerboard. The dimensions of * checkerboard are specified by the constant N_ROWS and * N_COLUMNS, and the size of the square is chosen so that * the checkerboard fills the available vertical space. */ import acm.graphics.*; import acm.program.*; public class Checkerboard extends GraphicsProgram { public void run() { double sqSize = (double) getHeight() / N_ROWS; /* square size */ for (int i = 0; i < N_ROWS; i++) { for (int j = 0; j < N_COLUMNS; j++) { /* draw (i,j)th square */ double x = j * sqSize; double y = i * sqSize; GRect sq = new GRect(x, y, sqSize, sqSize); sq.setFilled(((i + j) % 2) != 0); add(sq); } /* for j */ } /* for i */ } /* private constants */ private static final int N_ROWS = 8; private static final int N_COLUMNS = 8; }