Checkerboard

Retired DISLab
이동: 둘러보기, 찾기
/*
 * File: Checkerboard.java
 * -----------------------
 * This program draws a checkerboard. The dimensions of the
 * checkerboard are specified by the constans N_ROWS and
 * N_COLUMNS, and the size of the squares 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;
		for (int i = 0; i < N_ROWS; i++) {
			for(int j = 0; j < N_COLUMNS; j++) {
				double x = j * sqSize;
				double y = i * sqSize;
				GRect sq = new GRect(x, y, sqSize, sqSize);
				sq.setFilled((i + j) % 2 != 0);
				add(sq);
			}
		}
	}
 
	/* Private constants */
	private static final int N_ROWS = 8;
	private static final int N_COLUMNS = 8;
 
	private static final long serialVersionUID = 1;
}
개인 도구
이름공간
변수
행위
둘러보기
구성원
연구
연구실
기타
도구모음
인쇄/내보내기