// Tom Monin et Clément Martins // paintChoix V1 // class pour l'affichage de la selection des lignes, collonnes et nombre de mines import java.awt.*; import javax.swing.*; import javax.swing.JComponent; public class Case extends JComponent{ private boolean visibilite; private boolean bombe; private int voisin; private int suspition; private Image interogation, etoile, imgboombe; public Case(){ this.visibilite=false; this.bombe=false; this.voisin=0; this.suspition=0; this.interogation= Toolkit.getDefaultToolkit().getImage("./IMAGE/pointintero.png"); this.etoile= Toolkit.getDefaultToolkit().getImage("./IMAGE/etoile.png"); this.imgboombe= Toolkit.getDefaultToolkit().getImage("./IMAGE/bombe.png"); } public void setVisibiliter(boolean trueorfalse){ this.visibilite=trueorfalse; } public void setBombe(){ this.bombe=true; } public void suspition(){ this.suspition++; if(this.suspition==3){ this.suspition=0; } } public boolean getBombe(){ return this.bombe; } public void setVoisin(int nvoisin){ this.voisin=nvoisin; } public boolean getSuspition(){ if(this.suspition>0){ return true; }else{ return false; } } @Override protected void paintComponent(Graphics pinceau) { // obligatoire : on crée un nouveau pinceau pour pouvoir le modifier plus tard Graphics secondPinceau = pinceau.create(); // obligatoire : si le composant n'est pas censé être transparent if (this.isOpaque()) { // obligatoire : on repeint toute la surface avec la couleur de fond secondPinceau.setColor(this.getBackground()); secondPinceau.fillRect(0, 0, this.getWidth(), this.getHeight()); } if(this.visibilite==false){ secondPinceau.setColor(new Color(100,100,100)); secondPinceau.fillRect(0, 0, this.getWidth(), this.getHeight()); secondPinceau.setColor(new Color(200, 200, 200)); secondPinceau.fillRect(this.getWidth()/20, this.getHeight()/20, this.getWidth()/20*18, this.getHeight()/20*18); } if(this.visibilite==true){ secondPinceau.setColor(new Color(100,100,100)); secondPinceau.fillRect(0, 0, this.getWidth(), this.getHeight()); secondPinceau.setColor(new Color(255, 255, 255)); secondPinceau.fillRect(this.getWidth()/20, this.getHeight()/20, this.getWidth()/20*18, this.getHeight()/20*18); secondPinceau.setColor(new Color(255, 0, 0)); if(this.voisin>0){ secondPinceau.drawString(String.valueOf(voisin), this.getWidth()/2, this.getHeight()/2); } } if(this.suspition==1 && this.visibilite==false){ secondPinceau.drawImage(this.etoile, this.getWidth()/20*5, this.getHeight()/20*5, this.getWidth()/20*10, this.getHeight()/20*10 ,this); } if(this.suspition==2 && this.visibilite==false){ secondPinceau.drawImage(this.interogation, this.getWidth()/20*5, this.getHeight()/20*5, this.getWidth()/20*10, this.getHeight()/20*10 ,this); } if(this.bombe==true && this.visibilite==true){ secondPinceau.setColor(new Color(255,0,125)); secondPinceau.fillRect(this.getWidth()/20, this.getHeight()/20, this.getWidth()/20*18, this.getHeight()/20*18); secondPinceau.drawImage(this.imgboombe, this.getWidth()/20*5, this.getHeight()/20*5, this.getWidth()/20*10, this.getHeight()/20*10 ,this); } } }