import java.awt.*; // for Graphics, Color import javax.swing.*; // for JFrame, JPanel public class Ch13_3 // draw a Checkerboard { public static void main(String[] args) { JFrame frame=new JFrame("Exercise12_1"); // establish title for JFrame frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // establish what to do if JFrame is closed frame.setSize(340,360); // set size to something reasonable for this GUI CheckerPanel p1=new CheckerPanel(); frame.add(p1); // add the JPanel to this JFrame and make the JFrame visible frame.setVisible(true); } public static class CheckerPanel extends JPanel { public void paintComponent(Graphics g) { for(int i=0;i<8;i++) for(int j=0;j<8;j++) { if((i+j)%2==0) g.setColor(Color.red); else g.setColor(Color.black); g.fillRect(i*40,j*40,40,40); } } } }