Write a program to design a checkboard with the following criteria’s Displays a
ID: 3693973 • Letter: W
Question
Write a program to design a checkboard with the following criteria’s Displays a frame containing 64 squares arranged in eight rows and eight columns.
Each square is 25 pixels by 25 pixels.
The colors of the squares alternate between red and black, starting with a red square in the upper-left corner.
Sample code and guide for homework
//Download the jpb.zip folder unzip/extract all files and place in the same location as your Checkerboard program
// DOWNLOAD the JPB here http://grid.cs.gsu.edu/~csclxh/csc2010/AssignmentsSP16/jpb.zip
//This program will draw a checkerboard in a Drawable Frame of the size
//200 X 200 pixels in the colors of red and black you can set your own frame size
import java.awt.*;
import jpb.*;
public class Checkerboard { public static void main (String[] args) {
DrawableFrame df = new DrawableFrame("Checkerboard");
df.show();
df.setSize(200, 200);
Graphics g = df.getGraphicsContext();
// your code starts here
//your code end here
df.repaint(); }
}
Explanation / Answer
I hope this helps you a bit
int counter=1;
for (int i=0; i<1600; i++)
{
int j=1; int x=0;
if (counter>=9)
{
x+=24;
}
if(i>=200)
{
i=0;
}
if ((i + j) % 2 != 0)
{
g.setColor(Color.voilet);
g.fillRect(i, x, 20, 20);
i+=24;
}
else
{
g.setColor(Color.yellow);
g.fillRect(i, x, 20, 20);
i+=24;
}
counter++;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.