Skip to content

Instantly share code, notes, and snippets.

@jimmykurian
Created February 3, 2012 22:12
Show Gist options
  • Save jimmykurian/1733211 to your computer and use it in GitHub Desktop.
Save jimmykurian/1733211 to your computer and use it in GitHub Desktop.
A graphical application that displays a 8x8 chess board with 64 squares, alternating black and white.
//CheckerBoard.java - Jimmy Kurian
import javax.swing.*;
import java.awt.Graphics;
import java.awt.Color;
public class CheckerBoard extends JFrame
{
public void paint(Graphics g)
{
int row;
int col;
int x;
int y;
for ( row = 0; row < 9; row++ )
{
for ( col = 0; col < 8; col++)
{
x = col * 22;
y = row * 22;
if ( (row % 2) == (col % 2) )
g.setColor(Color.WHITE);
else
g.setColor(Color.BLACK);
g.fillRect(x, y, 22, 22);
}
}
}
public static void main(String args[]) {
CheckerBoard check = new CheckerBoard();
check.setTitle("CheckerBoard");
check.setSize(180, 200);
check.setDefaultCloseOperation(EXIT_ON_CLOSE);
check.setVisible(true);
}
}
@diptyajit-paul
Copy link

it's not working. can you pls send me the screen shot while the code is working?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment