Developpement/23DEV1.1/TPS2/TP01/MiseEnPage/Damier.java

32 lines
852 B
Java

import javax.swing.*;
import java.awt.*;
public class Damier{
public static void main(String[] args)
{
if(args.length <= 0)
{
System.err.println("number of line recquired");
System.exit(1);
}
int line = Integer.parseInt(args[0]);
JFrame fenetre = new JFrame("Damier");
fenetre.setLayout(new GridLayout(line, line));
GridLayout gestionnaire = new GridLayout(5, 5);
fenetre.setLayout(gestionnaire);
for(int i = 0 ; i<line ; i++){
for(int j = 0 ; j<line ; j++){
JPanel panel = new JPanel();
panel.setBackground((i+j)%2==0 ? Color.WHITE : Color.CYAN);
fenetre.add(panel);
}
}
fenetre.setSize(400, 400);
fenetre.setLocation(0, 0);
fenetre.setLocationRelativeTo(null);
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fenetre.setVisible(true);
}
}