-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cell.java
55 lines (49 loc) · 1 KB
/
Cell.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
/*
* Chapter 15.1
*/
import java.awt.Graphics;
import java.awt.Color;
//import java.awt.Canvas;
public class Cell
{
//Stable means the total number of live cells doesn't
//grow over time
private final int x;
private final int y;
private final int size;
private int state;
public static final Color[] COLORS = {Color.WHITE, Color.BLACK};
public Cell(int x, int y, int size)
{
this.x = x;
this.y = y;
this.size = size;
this.state = 0;
}
//takes a graphics context as a parameter
//??What does "context" mean here????????
public void draw(Graphics g)
{
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);
}
public boolean isOff()
{
//??WHY is this allowed? What is and isn't allowed?????
return state == 0;
}
public boolean isOn()
{
return state == 1;
}
public void turnOff()
{
state = 0;
}
public void turnOn()
{
state = 1;
}
}