SAE21_2021/Fond.java

48 lines
1.3 KiB
Java
Raw Normal View History

2022-04-27 12:04:45 +02:00
import javax.swing.*;
import java.awt.*;
2022-05-18 14:42:02 +02:00
public class Fond extends JPanel{
2022-04-27 12:04:45 +02:00
public Fond(JFrame fenetre) {
2022-04-27 17:25:07 +02:00
// On créer un damier aux couleurs du démineur pour le fond
2022-04-27 12:04:45 +02:00
// Découpage de la fenêtre pour la mise en place du damier
Dimension damierSize = fenetre.getSize();
Dimension gridSize = new Dimension(damierSize.width/75, damierSize.height/75);
2022-05-18 14:42:02 +02:00
GridLayout layoutDamier = new GridLayout(gridSize.height, gridSize.width);
this.setLayout(layoutDamier);
this.setSize(damierSize);
2022-04-27 12:04:45 +02:00
// Création des couleurs
Color gray1 = new Color(70,70,70);
Color gray2 = new Color(60,60,60);
// Réalisation du damier et ajout d'éléments graphiques
for (int line=0; line<gridSize.height; line++){
for(int cases = 0; cases < gridSize.width; cases++){
if (line%2==0){
if (cases%2==0){
JPanel dark = new JPanel();
dark.setBackground(gray2);
2022-05-18 14:42:02 +02:00
this.add(dark);
2022-04-27 12:04:45 +02:00
} else {
JPanel light = new JPanel();
light.setBackground(gray1);
2022-05-18 14:42:02 +02:00
this.add(light);
2022-04-27 12:04:45 +02:00
}
} else {
if (cases%2==0){
JPanel light = new JPanel();
light.setBackground(gray1);
2022-05-18 14:42:02 +02:00
this.add(light);
2022-04-27 12:04:45 +02:00
} else {
JPanel dark = new JPanel();
dark.setBackground(gray2);
2022-05-18 14:42:02 +02:00
this.add(dark);
2022-04-27 12:04:45 +02:00
}
}
}
}
}
}