APL/APL2.1/TP03/Damier/Damier.java

24 lines
726 B
Java
Raw Normal View History

2022-02-07 17:26:04 +01:00
import javax.swing.*;
import java.awt.*;
public class Damier {
public static void main(String[] args) {
int size = Integer.parseInt(args[0]);
JFrame fenetre = new JFrame("Damier");
fenetre.setSize(size * 50, size * 50);
fenetre.setLocation(100, 100);
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
GridLayout grid = new GridLayout(size, size);
fenetre.setLayout(grid);
for (int i = 0; i < size * size; i++) {
JPanel panel = new JPanel();
if (i % 2 == 0) panel.setBackground(Color.CYAN);
else panel.setBackground(Color.WHITE);
fenetre.add(panel);
}
fenetre.setVisible(true);
}
}