forked from ChrisMayfield/ThinkJavaCode2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDrawing.bak
56 lines (49 loc) · 1.14 KB
/
Drawing.bak
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
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;
import java.util.ArrayList;
/**
* Draws a collection of DrawablePolygons.
*/
public class Drawing extends Canvas {
private ArrayList<DrawablePolygon> list;
/**
* Constructs a drawing of given size.
*
* @param width the width in pixels
* @param height the height in pixels
*/
public Drawing(int width, int height) {
setSize(width, height);
setBackground(Color.WHITE);
list = new ArrayList<DrawablePolygon>();
}
/**
* Adds a new actor to the drawing.
*
* @param dp the object to add
*/
public void add(DrawablePolygon dp) {
list.add(dp);
}
/**
* Draws all the actors on the canvas.
*
* @param g graphics context
*/
@Override
public void paint(Graphics g) {
for (DrawablePolygon dp : list) {
dp.draw(g);
}
}
/**
* Calls the step method of each actor and updates the drawing.
*/
public void step() {
for (DrawablePolygon dp : list) {
dp.step();
}
repaint();
}
}