Advertisement
Guest User

Untitled

a guest
Jul 24th, 2014
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.82 KB | None | 0 0
  1. package testMethods;
  2.  
  3. import java.awt.Color;
  4. import java.awt.GridLayout;
  5.  
  6. import javax.swing.JFrame;
  7. import javax.swing.JPanel;
  8.  
  9. public class Chess extends JFrame {
  10.    
  11.     JPanel squares[][] = new JPanel[8][8];
  12.    
  13.     public Chess() {
  14.         this.setSize(500, 500);
  15.         this.setVisible(true);
  16.         this.setDefaultCloseOperation(EXIT_ON_CLOSE);
  17.         this.setLayout(new GridLayout(8,8));
  18.  
  19.         for (int i = 0; i < 8; i++) {
  20.             for (int j = 0; j < 8; j++) {
  21.                 squares[i][j] = new JPanel();
  22.  
  23.                 if ((i + j) % 2 == 0) {
  24.                     squares[i][j].setBackground(Color.black);
  25.                 } else {
  26.                     squares[i][j].setBackground(Color.white);
  27.                 }  
  28.                 this.add(squares[i][j]);
  29.             }
  30.         }
  31.     }
  32.  
  33.     public static void main(String[] args) {
  34.         new Chess();
  35.     }
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement