// Chess board - source code
// by Derek Molloy 2000

import java.awt.Graphics;
import java.applet.Applet;
import java.awt.Color;			//must import the color class to use it!

public class ChessBoard extends Applet
{
	
	public void paint(Graphics g)
	{
		int boxWidth = 20;	// the box width in pixels
		
		// this boolean is key to the solution, it must remember if the square is a black
		// or white square. The first square is black so it is set to true.

		boolean blackSquare = true;
		
		for (int y=0; y<8; y++) // for each row
		{
			for (int x=0; x<8; x++) // for each column
			{
				if (blackSquare) g.setColor(Color.black);  //if a blacksquare set the color black
				else g.setColor(Color.white); // otherwise set the colour white
				
				blackSquare = !blackSquare; // invert for the next square
				
				g.fillRect((x*boxWidth),(y*boxWidth),boxWidth,boxWidth);
				// fill the box with color
			}
			blackSquare = !blackSquare; // each row starts with a different colour!
		}
	}
	
	
}
