-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCercle.java
113 lines (89 loc) · 2.04 KB
/
Cercle.java
1
2
3
4
5
6
7
8
9
10
11
12
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
42
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package logicieldedessin;
import java.awt.Graphics;
import java.util.LinkedList;
/**
* @author freshloic
*
*/
public class Cercle extends Figure {
/**
*
*/
private static final long serialVersionUID = 6947876081184348818L;
private Point Centre;
private double rayon;
public Cercle(Point Centre, Point p, String nom){
this.Centre = Centre;
this.rayon = Centre.distance(p);
this.setNom(nom);
}
public Cercle(Point Centre, double rayon){
this.Centre = Centre;
this.rayon = rayon;
}
public Cercle(Point Centre, Point p){
this(Centre,p,"");
}
public void afficher()
{
System.out.println(toString());
}
public String toString(){
return getNom() + " r =" + rayon + " " + Centre;
}
public Point getCentre() {
return Centre;
}
public double getRayon() {
return rayon;
}
public void setRayon(double rayon) {
this.rayon = rayon;
}
public LinkedList<Point> getPoints() {
LinkedList<Point> liste = new LinkedList<Point>();
liste.add(this.Centre);
return liste;
}
/* (non-Javadoc)
* @see monpremierprojet.Figure#translater(double, double)
*/
public void translater(double dx, double dy) {
Centre.translater(dx, dy);
}
/**
* @param c
* @return
*/
public boolean equals(Cercle c){
if(c != null)
return this.Centre.equals(c.Centre) && this.rayon == c.rayon;
else
return false;
}
/* (non-Javadoc)
* @see java.lang.Object#clone()
*/
public Object cloner(){
Cercle ob = null;
try {
ob = (Cercle) super.clone();
ob.Centre = (Point) Centre.cloner();
} catch (CloneNotSupportedException e) {
e.printStackTrace();
}
return ob;
}
@Override
public void paint(Graphics gc) {
if(getCouleur() != null) gc.setColor(getCouleur());
gc.drawString(getNom(), (int)Centre.getX(), (int)Centre.getY());
gc.drawOval((int)Centre.getX() - (int)rayon, (int)Centre.getY() - (int)rayon, (int)rayon*2, (int)rayon*2);
}
@Override
public int compareTo(Object o) {
return (int) (rayon - ((Cercle) o).rayon);
}
@Override
public int getPoids() { return this.getPoints().size(); }
}