Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

JAVA problem. this is everything i have. plz complete it. Write a program using

ID: 3861348 • Letter: J

Question

JAVA problem. this is everything i have. plz complete it.

Write a program using the DrawingPanel that contains a method for drawing a checkerboard.

The checkerboard should be 160 units wide (and tall) and should have an input parameters that allow the method to place the checkerboard at any x and y coordinates. For example you should be able to do the following in your main program.

drawCheckerboard(100,100, myG);

drawCheckerboard(120,500, myG);

To draw two different checkerboards.

You may choose your own colors for the squares on the checkerboard.

Explanation / Answer

import javax.swing.*; import java.awt.*; public class Checkerboard extends JApplet { private static final long serialVersionUID = 1L; private final int DIMENSION = 8; // Want 8 x 8 board private final int SQUARE_SIZE = 30; // Each square is 30 x 30 pixels /** * Set up canvas. */ public void init() { // Set the size of the applet to be exactly the checkerboard size. setSize(DIMENSION * SQUARE_SIZE, DIMENSION * SQUARE_SIZE); Container cp = getContentPane(); // Content pane holds components cp.add(new Canvas()); // The canvas is the only component setVisible(true); // Makes the applet (and its components) visible } /** * Serves as the drawing canvas for the checkerboard. */ private class Canvas extends JPanel { private static final long serialVersionUID = 1L; /** * Paints the checkerboard. * @param page the Graphics object that we draw on. */ public void paintComponent(Graphics page) { super.paintComponent(page); // Draw all the black and red squares. drawCheckerboard(page); } /** * Draw the entire checkerboard in black and red. * @param page the graphics object to draw on */ public void drawCheckerboard(Graphics page) { Color squareColor; // Color of the current square for (int row = 0; row