forked from ChrisMayfield/ThinkJavaCode2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDrawablePolygon.java
More file actions
95 lines (79 loc) · 1.96 KB
/
Copy pathDrawablePolygon.java
File metadata and controls
95 lines (79 loc) · 1.96 KB
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
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Polygon;
/**
* Specialization of Polygon that has a color and the ability to draw itself.
*/
public class DrawablePolygon extends Polygon implements Actor {
protected Color color;
/**
* Creates an empty polygon.
*/
public DrawablePolygon() {
super();
color = Color.GRAY;
}
public void collides(Actor a){}
/**
* Returns a string of point coordinates and color.
*/
public String toString(){
String result = "A polygon with the following points: ";
for(int i = 0; i < xpoints.length; i++){
result += "(" + xpoints[i] + ", " + ypoints[i] + ")";
}
return result;
}
/**
* Draws the polygon on the screen.
*
* @param g graphics context
*/
public void draw(Graphics g) {
g.setColor(color);
g.fillPolygon(this);
}
@Override
public void step() {
// do nothing
}
/**
* Test code that creates a ColorPolygon.
*
* @param args command-line arguments
*/
public static void main(String[] args) {
DrawablePolygon p = new DrawablePolygon();
p.addPoint(57, 110);
p.addPoint(100, 35);
p.addPoint(143, 110);
p.color = Color.GREEN;
System.out.println(p);
}
@Override
public int getx() {
return this.xpoints[0];
}
@Override
public int gety() {
return this.ypoints[0];
}
@Override
public int getdx() {
return 0;
}
@Override
public int getdy() {
return 0;
}
@Override
public void setdx(int n) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'setdx'");
}
@Override
public void setdy(int n) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'setdy'");
}
}