Created
February 3, 2012 22:12
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
it's not working. can you pls send me the screen shot while the code is working?