import java.applet.Applet; import java.awt.Graphics; import java.awt.Graphics2D; import javax.swing.JOptionPane; /** An applet that draws a checkerboard of two colors -- one chosen by the user and one that is the complement of the first color. */ public class CheckerboardApplet extends Applet { private Checkerboard board; public CheckerboardApplet() { String input; // ask the user for the size & location of the board input = JOptionPane.showInputDialog( "What is the size of the checkerboard?"); int size = Integer.parseInt(input); input = JOptionPane.showInputDialog( "Where is the top of the checkerboard?"); int top = Integer.parseInt(input); input = JOptionPane.showInputDialog( "Where is the left side of the checkerboard?"); int left = Integer.parseInt(input); // construct a checkerboard and draw it board = new Checkerboard(top, left, size); } public void paint(Graphics g) { // recover Graphics2D Graphics2D g2 = (Graphics2D)g; board.draw(g2); } }