- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCell.java
More file actions
Latest commit
55 lines (49 loc) · 1 KB
/
Copy pathCell.java
File metadata and controls
55 lines (49 loc) · 1 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
/*
* Chapter 15.1
*/
importjava.awt.Graphics;
importjava.awt.Color;
//import java.awt.Canvas;
publicclassCell
{
//Stable means the total number of live cells doesn't
//grow over time
privatefinalintx;
privatefinalinty;
privatefinalintsize;
privateintstate;
publicstaticfinalColor[] COLORS = {Color.WHITE, Color.BLACK};
publicCell(intx, inty, intsize)
{
this.x = x;
this.y = y;
this.size = size;
this.state = 0;
}
//takes a graphics context as a parameter
//??What does "context" mean here????????
publicvoiddraw(Graphicsg)
{
g.setColor(COLORS[state]);
g.fillRect(x + 1, y + 1, size - 1, size - 1);
g.setColor(Color.LIGHT_GRAY);
g.drawRect(x, y, size, size);
}
publicbooleanisOff()
{
//??WHY is this allowed? What is and isn't allowed?????
returnstate == 0;
}
publicbooleanisOn()
{
returnstate == 1;
}
publicvoidturnOff()
{
state = 0;
}
publicvoidturnOn()
{
state = 1;
}
}