forked from ChrisMayfield/ThinkJavaCode2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDrawing.java
More file actions
43 lines (37 loc) · 873 Bytes
/
Drawing.java
File metadata and controls
43 lines (37 loc) · 873 Bytes
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
import java.awt.Canvas;
import java.awt.Graphics;
/**
* Drawing of a grid.
*/
public class Drawing extends Canvas {
private Grid grid;
/**
* Constructs a drawing for the grid.
*
* @param grid the initialized grid
*/
public Drawing(Grid grid) {
this.grid = grid;
setSize(grid.width(), grid.height());
}
/**
* Draws the grid, cell by cell.
*
* @param g graphics context
*/
@Override
public void paint(Graphics g) {
grid.draw(g);
}
/**
* Overriding this method helps the simulation run more smoothly. Normally
* the Canvas is cleared before painting, but there is no need to clear it
* since paint draws the entire grid.
*
* @param g graphics context
*/
@Override
public void update(Graphics g) {
grid.draw(g);
}
}