Write a program to design a checkboard with the following criteria’s * Displays
ID: 3574551 • 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
COMMENT WHAT EACH LINE DOES PLEASEEEE*********
________________________________________________________________________________________________________________
//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
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();
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)
{
//Use setColor and fillRect methods to
//fill the specified colors in rectangular
//boxes
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++;
}
df.repaint();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.