diff --git a/Case.java b/Case.java index 6940816..01b43af 100644 --- a/Case.java +++ b/Case.java @@ -3,16 +3,19 @@ import java.awt.*; public class Case extends JComponent { private JPanel panel = new JPanel(); - private int entourage=0; - private boolean visible=false; - private boolean minee=false; + private int entourage; + private boolean visible; + private boolean minee; public Case(Dimension caseSize, boolean visible, boolean minee, int entourage) { super(); - this.panel.setSize(caseSize); this.entourage=entourage; this.visible=visible; this.minee=minee; + this.panel.setSize(caseSize); + + GridLayout unique = new GridLayout(1,1); + this.panel.setLayout(unique); if (this.visible == false) { Color gray2 = new Color(70, 70, 70); @@ -25,16 +28,12 @@ public class Case extends JComponent { this.panel.setBackground(rose); } else if (this.entourage>0){ System.out.println(""+ this.entourage); + this.panel.add(new Chiffre(entourage,caseSize)); } } } - @Override - protected void paintComponent(Graphics pinceau) { - System.out.println("coucou"); - } - public JPanel getCase() { return this.panel; } diff --git a/Chiffre.java b/Chiffre.java new file mode 100644 index 0000000..4a50691 --- /dev/null +++ b/Chiffre.java @@ -0,0 +1,22 @@ +import javax.swing.JComponent; +import java.awt.*; + +public class Chiffre extends JComponent { + private int entourage; + private Dimension caseSize; + public Chiffre(int entourage, Dimension caseSize) { + super(); + this.entourage = entourage; + this.caseSize=caseSize; + } + @Override + protected void paintComponent(Graphics pinceau) { + Graphics chiffre = pinceau.create(); + Font font = new Font("Arial", Font.BOLD, 40); + chiffre.setFont(font); + Color jaune = new Color(236, 214, 0); + chiffre.setColor(jaune); + chiffre.drawString(Integer.toString(this.entourage),caseSize.width/3,caseSize.height*8/10); + System.out.println(""+caseSize); + } +} diff --git a/Etoile.java b/Etoile.java index bf83f9a..19aae62 100644 --- a/Etoile.java +++ b/Etoile.java @@ -5,13 +5,15 @@ import java.awt.*; // Création d'un Jcomponent Etoile, qui sert pour le marquage des mines public class Etoile extends JComponent { private Image etoileImage; - public Etoile() { + private Dimension caseSize; + public Etoile(Dimension caseSize) { super(); + this.caseSize=caseSize; this.etoileImage = Toolkit.getDefaultToolkit().getImage("etoile.png"); } @Override protected void paintComponent(Graphics pinceau) { Graphics etoile = pinceau.create(); - etoile.drawImage(this.etoileImage,5,10,90,80,this); + etoile.drawImage(this.etoileImage,this.caseSize.width*1/20,this.caseSize.height*1/10,this.caseSize.width*9/10,this.caseSize.height*8/10,this); } } \ No newline at end of file diff --git a/Grille.java b/Grille.java index 351c725..2190bb1 100644 --- a/Grille.java +++ b/Grille.java @@ -6,7 +6,7 @@ public class Grille extends JComponent { private Dimension grilleSize=new Dimension(0,0); private JPanel grille= new JPanel(); - // On créer La grille de jeu + // On crée La grille de jeu public Grille(int lignes, int colonnes, int mines){ // Découpage de l'espace en fonction des paramètres pour la mise en place de la grille @@ -90,12 +90,16 @@ public class Grille extends JComponent { } } - // Affichage des cases - for (int i=0;i