Advertisement
Guest User

Untitled

a guest
Feb 21st, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. package mvc;
  2.  
  3. import javax.swing.JPanel;
  4.  
  5. import java.awt.*;
  6.  
  7. public class VueFeu extends JPanel implements EcouteurModele {
  8.  
  9. /**
  10. * Attributs
  11. */
  12. private static final long serialVersionUID = 6026640940149134871L;
  13. public Color[] couleur = {Color.red, Color.orange, Color.green};
  14. public FeuTricolore feuTri;
  15. public int rayon;
  16. public final static int DIM = 100;
  17. public final static int NB_COLORS = 3;
  18.  
  19.  
  20.  
  21. public VueFeu(FeuTricolore feuTri) {
  22. super();
  23. this.feuTri = feuTri;
  24. feuTri.ajoutEcouteur(this);
  25. this.rayon = DIM;
  26. this.setPreferredSize(new Dimension(DIM, NB_COLORS * DIM));
  27. this.repaint();
  28. }
  29.  
  30.  
  31. @Override
  32. public void paintComponents(Graphics g) {
  33. super.paintComponents(g);
  34. /* int y = 0;
  35. g.setColor(Color.darkGray);
  36.  
  37. for (int i = 0; i < couleur.length; i++) {
  38. g.fillOval(0, y, this.rayon ,this.rayon);
  39. y += rayon;
  40.  
  41. int index = this.feuTri.couleur.ordinal();
  42. g.setColor(couleur[index]);
  43.  
  44. g.fillOval(0, index * this.rayon, this.rayon, this.rayon);
  45. }*/
  46.  
  47. int w = (int) this.getSize().getWidth();
  48.  
  49. // Contour du feu
  50. for (int i = 0; i < NB_COLORS; i++) {
  51. g.drawOval((w-DIM)/2, i*DIM, DIM, DIM); // La 1ere valeur permet de centrer une image
  52. }
  53.  
  54.  
  55. // Couleur du feu
  56. int colorNum = -1;
  57. switch (feuTri.getCouleur()) {
  58. case ROUGE:
  59. colorNum = 0;
  60. g.setColor(Color.RED);
  61. break;
  62.  
  63. case ORANGE:
  64. colorNum = 1;
  65. g.setColor(Color.ORANGE);
  66. break;
  67.  
  68. case VERT:
  69. colorNum = 2;
  70. g.setColor(Color.GREEN);
  71. }
  72. g.fillOval((w-DIM)/2, colorNum*DIM, DIM, DIM);
  73. }
  74.  
  75. @Override
  76. public void ModelMisAjour(ModeleEcoutable source) { // param object especially ModeleEcoutable
  77. this.repaint();
  78. }
  79.  
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement