/* * File: TicTacToeBoard.java * ------------------------- * This program draws a Tic-Tac-Toe board at the center of the window. * This version uses constant for better programming style * * Author: CS1MD3, Sept. 2008 */ import acm.graphics.*; import acm.program.*; public class TicTacToeBoard extends GraphicsProgram { public void run() { /* gap between lines */ int gap = BOARD_SIZE / 3; /* coordinates of the upper-left corner of the board */ int x = (getWidth() - BOARD_SIZE) / 2; int y = (getHeight() - BOARD_SIZE) / 2; /* draw horizontal lines */ add(new GLine(x, y + gap, x + BOARD_SIZE , y + gap)); add(new GLine(x, y + 2*gap, x + BOARD_SIZE, y + 2*gap)); /* draw vertical lines */ add(new GLine(x + gap, y, x + gap, y + BOARD_SIZE)); add(new GLine(x + 2*gap, y, x + 2*gap, y + BOARD_SIZE)); } /* constant BOARD_SIZE */ private static final int BOARD_SIZE = 180; }