SAE21_2022/Cellules.java

83 lines
2.0 KiB
Java
Raw Normal View History

import java.awt.Color;
import javax.swing.JComponent;
import java.awt.Graphics;
public class Cellules extends JComponent{
public static final int COULOIR=0;
public static final int MUR=1;
public static final int ENTREE=2;
public static final int SORTIE=3;
public static final int DESSUS=10;
public static final int VUE=11;
public static final boolean LIBRE = false;
public static final boolean OCCUPE = true;
private Color backgroundColor;
private int cetteLigne;
private int cetteColone;
private int ceType;
public Cellules(int uneLigne, int uneColone, int type){
super();
this.cetteLigne=uneLigne;
this.cetteColone=uneColone;
this.ceType = type;
peindre(ceType);
}
public int getLigne(){
return this.cetteLigne;
}
public int getColone(){
return this.cetteColone;
}
public int getType(){
return this.ceType;
}
public void setType(int newType){
if(newType==COULOIR){
this.ceType = COULOIR;
} else if(newType==MUR){
this.ceType = MUR;
} else if(newType==ENTREE){
this.ceType = ENTREE;
} else if(newType==SORTIE){
this.ceType = SORTIE;
}
}
public void peindre(int peinture){
if(peinture==COULOIR){
backgroundColor = Color.WHITE;
} else if(peinture==MUR){
backgroundColor = Color.BLACK;
} else if(peinture==ENTREE){
backgroundColor = Color.BLUE;
} else if(peinture==SORTIE){
backgroundColor = Color.RED;
} else if(peinture==VUE){
backgroundColor = Color.YELLOW;
} else if(peinture==DESSUS){
backgroundColor = Color.ORANGE;
}
repaint();
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(backgroundColor);
g.fillRect(0, 0, getWidth(), getHeight());
}
}