SAE21_2022/Cellules.java

73 lines
1.7 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;
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;
}
repaint();
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(backgroundColor);
g.fillRect(0, 0, getWidth(), getHeight());
}
}