import java.awt.Frame; import java.awt.AWTEvent; import java.awt.event.WindowEvent; import java.awt.Canvas; import java.awt.Graphics; import java.awt.Color; import java.awt.Rectangle; public class CheckerBoard extends Frame{ public static void main(String[] args) { new CheckerBoard(); } CheckerBoard() { enableEvents(AWTEvent.WINDOW_EVENT_MASK); Squares squares = new Squares(); add(squares); pack(); show(); } public void processWindowEvent(WindowEvent event) { if(event.getID() == WindowEvent.WINDOW_CLOSING) { System.exit(0); } } } class Squares extends Canvas { Squares() { setSize(400,400); } public void paint(Graphics g) { Rectangle b = getBounds(); int height = b.height / 4; int width = b.width / 4; int x = 0; int y = 0; int count = 0; Color Black = Color.black; Color White = Color.white; for(int o = 0; o < 4;o++) { for(int i =0; i < 4; i++,x+=height,count++) { //Checks to see if the count Variable is even if(count%2 == 0) { g.setColor(Black); } else { g.setColor(White); } g.fillRect(x, y, width, height); } count++; x=0; y+=width; } } }