Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package mvc;
- import javax.swing.JPanel;
- import java.awt.*;
- public class VueFeu extends JPanel implements EcouteurModele {
- /**
- * Attributs
- */
- private static final long serialVersionUID = 6026640940149134871L;
- public Color[] couleur = {Color.red, Color.orange, Color.green};
- public FeuTricolore feuTri;
- public int rayon;
- public final static int DIM = 100;
- public final static int NB_COLORS = 3;
- public VueFeu(FeuTricolore feuTri) {
- super();
- this.feuTri = feuTri;
- feuTri.ajoutEcouteur(this);
- this.rayon = DIM;
- this.setPreferredSize(new Dimension(DIM, NB_COLORS * DIM));
- this.repaint();
- }
- @Override
- public void paintComponents(Graphics g) {
- super.paintComponents(g);
- /* int y = 0;
- g.setColor(Color.darkGray);
- for (int i = 0; i < couleur.length; i++) {
- g.fillOval(0, y, this.rayon ,this.rayon);
- y += rayon;
- int index = this.feuTri.couleur.ordinal();
- g.setColor(couleur[index]);
- g.fillOval(0, index * this.rayon, this.rayon, this.rayon);
- }*/
- int w = (int) this.getSize().getWidth();
- // Contour du feu
- for (int i = 0; i < NB_COLORS; i++) {
- g.drawOval((w-DIM)/2, i*DIM, DIM, DIM); // La 1ere valeur permet de centrer une image
- }
- // Couleur du feu
- int colorNum = -1;
- switch (feuTri.getCouleur()) {
- case ROUGE:
- colorNum = 0;
- g.setColor(Color.RED);
- break;
- case ORANGE:
- colorNum = 1;
- g.setColor(Color.ORANGE);
- break;
- case VERT:
- colorNum = 2;
- g.setColor(Color.GREEN);
- }
- g.fillOval((w-DIM)/2, colorNum*DIM, DIM, DIM);
- }
- @Override
- public void ModelMisAjour(ModeleEcoutable source) { // param object especially ModeleEcoutable
- this.repaint();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement