-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCell.java
60 lines (49 loc) · 1.17 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
56
57
58
59
60
package four;
import javax.swing.*;
import java.awt.*;
public class Cell extends JButton {
public static final Color BACKGROUND = Color.LIGHT_GRAY;
public static final Color HIGHLIGHT = Color.CYAN;
private int row;
private int column;
private Content content;
Cell(int i, int j) {
super();
this.row = i;
this.column = j;
this.content = Content.EMPTY;
setName("Button" + (char) ('A' + j) + (i + 1));
setText();
setFocusPainted(false);
setBackground();
}
private void setText() {
setText(this.content.getText());
}
public int getRow() {
return row;
}
public int getColumn() {
return column;
}
Content getContent() {
return this.content;
}
void setContent(Content content) {
this.content = content;
setText();
}
boolean isEmpty() {
return this.content.equals(Content.EMPTY);
}
void highlight() {
setBackground(HIGHLIGHT);
}
void setBackground() {
setBackground(BACKGROUND);
}
void reset() {
setContent(Content.EMPTY);
setBackground();
}
}