// File name: Ch03Ex05Ans.java // This file contains a minimal shell for completing // DE Exercise 5 in Chapter 3. This program shell will // not produce any output until you add your code. // Note that this program is our first applet exercise. // Applets extend the Applet class, and don't have a // main method, since applets aren't applications. import java.awt.*; import java.applet.Applet; public class Ch03Ex05Ans extends Applet { /* This applet draws a red-and-black checkerboard. It is assumed that the size of the applet is 160 by 160 pixels. */ public void paint(Graphics g) { int row; // Row number, from 0 to 7 int col; // Column number, from 0 to 7 int x,y; // Top-left corner of square for ( row = 0; row < 8; row++ ) { for ( col = 0; col < 8; col++) { x = col * 20; y = row * 20; if ( (row % 2) == (col % 2) ) g.setColor(Color.red); else g.setColor(Color.black); g.fillRect(x, y, 20, 20); } } // end for row } // end paint() } // end class