DEV/DEV2.1/TP4/Damier.java

34 lines
720 B
Java
Raw Permalink Normal View History

2023-03-27 11:21:24 +02:00
import javax.swing.*;
import java.awt.*;
public class Damier {
public static void main(String[] args) {
int taille = Integer.parseInt(args[0]);
JFrame fenetre = new JFrame();
fenetre.setSize(500, 500);
fenetre.setLocation(0, 0);
GridLayout main = new GridLayout(taille,taille);
fenetre.setLayout(main);
for (int i = 0;i<taille;i++)
{
for (int j = 0;j<taille;j++)
{
JPanel temp = new JPanel();
if ((i+j)%2==0)
{
temp.setBackground(Color.CYAN);
}
else
{
temp.setBackground(Color.WHITE);
}
fenetre.add(temp);
}
}
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fenetre.setVisible(true);
}
}