1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
| public class dame {
public static void main (String[]arg){
Frame f = new Frame();
Panel grille[][] = new Panel [10][10];
Panel damier = new Panel();
Panel east = new Panel();
Panel west = new Panel();
Panel south = new Panel();
Panel north = new Panel();
Color c ;
int i, j;
f.setLayout(new BorderLayout());
f.setTitle("Dame");
f.setSize(new Dimension(600, 600));
f.setResizable(false);
damier.setLayout(new GridLayout(10,10));
//boucle pour avoir une grille de 10 colonnes sur 10 lignes
for (i = 0; i<10; i++){
for (j = 0; j<10; j++) {
grille[i][j] = new Panel();
if ( grille[0,2,4,6,8] [0,2,4,6,8]){
grille[i][j].setBackground(Color.green);
damier.add(grille[i][j]);
}
if ( grille[1,3,5,7,9] [1,3,5,7,9]){
grille[i][j].setBackground(Color.green);
damier.add(grille[i][j]);
}
else{
grille[i][j].setBackground(Color.black);
damier.add(grille[i][j]);
}
}
}
f.add(damier,BorderLayout.CENTER);
f.add(east,BorderLayout.EAST);
f.add(west,BorderLayout.SOUTH);
f.add(south,BorderLayout.WEST);
f.add(north,BorderLayout.NORTH);
// pour fermer la fenetre
f.addWindowListener
(
new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
}
);
f.setVisible(true);
}
} |
Partager