// Draw a checker board with each square randomly colored import java.awt.*; import java.applet.*; public class RandBoard extends Applet { public void paint( Graphics g ) { int size = 40; // The edge length of the squares int xOff = 40; // Starting x-coordinate int yOff = 40; // Starting y-coordinate int n = 8; // n X n board int xPos, yPos; // Draw 8 rows of squares for (yPos = yOff; yPos < yOff + n*size; yPos += size ) { // Draw a row of randomly colored squares for (xPos = xOff; xPos < xOff + n*size; xPos += size ) { // set color g.setColor( randomColor() ); // Draw square g.fillRect(xPos, yPos, size, size); } } } // randomColor() returns a random Color object public Color randomColor() { float red = (float) Math.random(); float green = (float) Math.random(); float blue = (float) Math.random(); return new Color( red, green, blue ); } }