Blame view

src/tp2/ArdoiseMagique/ArdoiseMagique.java 1.61 KB
5d736557   shaggy42089   tp2 done
1
2
3
4
5
6
  package tp2.ArdoiseMagique; /**
   * ArdoiseMagique.java
   *
   * @author <a href="mailto:gery.casiez@lifl.fr">Gery Casiez</a>
   * @version
   */
3c9d20ad   shaggy42089   nearly finished tp2
7
  
3c9d20ad   shaggy42089   nearly finished tp2
8
  import java.awt.*;
5d736557   shaggy42089   tp2 done
9
10
11
  import javax.swing.*;
  import java.util.ArrayList;
  import java.util.Iterator;
3c9d20ad   shaggy42089   nearly finished tp2
12
  
5d736557   shaggy42089   tp2 done
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
  class Point {
    public Integer x,y;
  
    Point() {
      x = 0;
      y = 0;
    }
  
    Point(Integer x, Integer y) {
      this.x = x;
      this.y = y;
    }
  }
  
  class Curve {
    public ArrayList<Point> points;
  
    Curve() {
      points = new ArrayList<Point>();
    }
  
    public void addPoint(Point P) {
      points.add(P);
    }
  
    public void clear() {
      points.clear();
    }
  }
3c9d20ad   shaggy42089   nearly finished tp2
42
  
5d736557   shaggy42089   tp2 done
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
  public class ArdoiseMagique extends JPanel {
    private ArrayList<Curve> curves;
  
    public ArdoiseMagique(){
      curves = new ArrayList<Curve>();
      curves.add(new Curve());
      setBackground(Color.white);
    }
  
    public void addPoint(Integer x, Integer y) {
      curves.get(curves.size()-1).addPoint(new Point(x,y));
      repaint();
    }
  
    public void newCurve() {
      curves.add(new Curve());
    }
  
    public void clear() {
      curves.clear();
      curves.add(new Curve());
      repaint();
    }
  
    public void paintComponent(Graphics g) {
      Point Pprev, Pcurrent;
      super.paintComponent(g);
  
      Iterator<Curve> itcurve = curves.iterator();
  
      Pprev = new Point();
  
      // Pour chaque courbe
      while (itcurve.hasNext()) {
        Iterator<Point> it = itcurve.next().points.iterator();
  
        if (it.hasNext()) {
          Pprev = it.next();
        }
  
        // Dessine les points d'une courbe
        while (it.hasNext()) {
          Pcurrent = it.next();
          g.drawLine(Pprev.x,Pprev.y, Pcurrent.x, Pcurrent.y);
          Pprev = Pcurrent;
        }
      }
    }
3c9d20ad   shaggy42089   nearly finished tp2
91
  }