Files
DEV/DEV.2.1/TP/TP3-MiseenPage/Damier.java

34 lines
748 B
Java
Raw Normal View History

2025-01-30 15:58:46 +01:00
import javax.swing.*;
import java.awt.*;
public class Damier {
public static void main(String[] args){
JFrame frame = new JFrame("Damier");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
int xpan = Integer.parseInt(args[0]);
int ypan;
ypan = xpan;
GridLayout gestionnaire = new GridLayout(xpan, ypan);
frame.setLayout(gestionnaire);
for(int i = 0; i < xpan*ypan; i++){
if(i % 2 == 0){
JPanel panneau = new JPanel();
panneau.setBackground(Color.WHITE);
frame.add(panneau);
}else{
JPanel panneau = new JPanel();
panneau.setBackground(Color.CYAN);
frame.add(panneau);
}
}
frame.setSize(500,500);
frame.setLocation(500,250);
frame.setVisible(true);
}
}