Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package testMethods;
- import java.awt.Color;
- import java.awt.GridLayout;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- public class Chess extends JFrame {
- JPanel squares[][] = new JPanel[8][8];
- public Chess() {
- this.setSize(500, 500);
- this.setVisible(true);
- this.setDefaultCloseOperation(EXIT_ON_CLOSE);
- this.setLayout(new GridLayout(8,8));
- for (int i = 0; i < 8; i++) {
- for (int j = 0; j < 8; j++) {
- squares[i][j] = new JPanel();
- if ((i + j) % 2 == 0) {
- squares[i][j].setBackground(Color.black);
- } else {
- squares[i][j].setBackground(Color.white);
- }
- this.add(squares[i][j]);
- }
- }
- }
- public static void main(String[] args) {
- new Chess();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement