-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCell.java
109 lines (74 loc) · 2.12 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
File name: Cell.java
Author: Nafis Saadiq Bhuiyan
Colby ID: 778267
Course: CS231B
Lab Section: CS231LC
Project 4
*/
import java.awt.Graphics;
import java.awt.Color;
public class Cell {
int rowIndex;
int columnIndex;
int value;
boolean locked;
public Cell() {
this.rowIndex = 0;
this.columnIndex = 0;
this.value = 0;
this.locked = false;
}
public Cell(int row, int col, int value) {
this.rowIndex = row;
this.columnIndex = col;
this.value = value;
this.locked = false;
}
public Cell(int row, int col, int value, boolean locked) {
this.rowIndex = row;
this.columnIndex = col;
this.value = value;
this.locked = locked;
}
// return the Cell's row index.
public int getRow() {
return this.rowIndex;
}
//return the Cell's column index.
public int getCol() {
return this.columnIndex;
}
//return the Cell's value.
public int getValue() {
return this.value;
}
//set the Cell's value
public void setValue(int newval) {
this.value = newval;
}
//return the value of the locked field
public boolean isLocked() {
return this.locked;
}
//set the cell as the parameter given
public void setLocked(boolean lock) {
this.locked = lock;
}
public String toString() {
String result = "";
result += this.value;
//result += "Row = "+this.rowIndex+ ", Column = " + this.columnIndex+ ", Cell value = "+ this.value + ", Locked = " + this.locked;
return result;
}
public void draw(Graphics g, int x, int y, int scale){
g.setColor(locked? Color.BLUE : Color.RED);
char[] out = (""+getValue()).toCharArray();
g.drawChars(out, 0, out.length, x, y);
}
// public void draw(Graphics g, int x, int y, int scale){
// char toDraw = (char) ((int) '0' + getValue());
// g.setColor(isLocked()? Color.BLUE : Color.RED);
// g.drawChars(new char[] {toDraw}, 0, 1, x, y);
// }
}