import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.geom.*;

public class Checkerboard {
    public static void main(String[] args) {
	JFrame frame = new JFrame("Checkerboard"); 
	BoardCanvas canvas = new BoardCanvas();

	frame.setSize(600,600);
	frame.getContentPane().add(canvas);
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	frame.setVisible(true);
    }	
}

class BoardCanvas extends JPanel {
    public void paintComponent(Graphics g) {
	Graphics2D g2 = (Graphics2D) g;
	int hBorderHeight = (int)(getHeight() * (BORDER_PCT / 2)); 
	int vBorderWidth = (int)(getWidth() * (BORDER_PCT / 2)); 
	int upperLeftBoardX = vBorderWidth;
	int upperLeftBoardY = hBorderHeight;
	int boxHeight = (getHeight() - 2 * hBorderHeight) / BOARD_SIZE;
	int boxWidth = (getWidth() - 2 * vBorderWidth) / BOARD_SIZE;
	setBackground(Color.GREEN);
	
	for (int rows= 0; rows < BOARD_SIZE; rows++)
	    for (int cols= 0; cols < BOARD_SIZE; cols++) {
		g2.setPaint(rows % 2 == 0 ^ cols % 2  == 0 ? Color.BLACK : Color.WHITE);
		Rectangle2D rect = new Rectangle2D.Float(upperLeftBoardX + cols * boxWidth,
							 upperLeftBoardY + rows * boxHeight,
							 boxWidth, boxHeight);
		g2.fill(rect);
	    }
    }
    
    private static double BORDER_PCT= .1;	
    private int hBorderHeight, vBorderWidth;	
    private int boxWidth, boxHeight;
    private static final int BOARD_SIZE = 8;
}
