-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLetter.java
More file actions
executable file
·123 lines (107 loc) · 2.37 KB
/
Letter.java
File metadata and controls
executable file
·123 lines (107 loc) · 2.37 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
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import java.awt.Color;
import java.util.Random;
import javax.swing.JLabel;
/**
* Date: 5/15/2012
* Implementation of each Letter represented on the Grid
* @author Michelle Perz
*/
public class Letter extends JLabel {
char myLetter;
private static final long serialVersionUID = 851346948984053215L;
public boolean clicked = false;
public boolean isPartOfWord = false;
public boolean isSolved = false;
public static boolean debug = false;
/**
* Constructor which sets sets the background color of the grid to white
* and assigns random characters to it
*/
public Letter () {
Random r = new Random();
char c = (char) (r.nextInt(26) + 'A');
this.setValue(c);
this.setOpaque(true);
this.setBackground(Color.white);
}
/**
* @return value of character object
*/
public Character getValue () {
return myLetter;
}
/**
* Sets the value of a character
* @param x where x is a character
*/
public void setValue (char x) {
myLetter = x;
setText(String.valueOf(myLetter));
}
/**
* Method which allows the user to click back and forth
*/
public void toggleClicked() {
if (! this.isClicked()) {
this.setClicked(true);
} else {
this.setClicked(false);
}
}
/**
* Debug method to change background method to yellow
*/
public void setDebug() {
if (debug)
this.setBackground(Color.yellow);
}
/**
* Debug method to change background method to orange
*/
public void setDebugColl() {
if (debug)
this.setBackground(Color.orange);
}
/**
* @return True if Letter was clicked on
*/
public boolean isClicked() {
return clicked;
}
/**
* @return True if Word matches word in word bank
*/
public boolean isSolved() {
return isSolved;
}
/**
* Method which changes background color if user clicks on box
* @param clicked if user clicks
*/
public void setClicked(boolean clicked) {
if (!isSolved) {
if (clicked) {
this.setBackground(Color.red);
} else {
this.setBackground(Color.white);
}
this.clicked = clicked;
} else {
this.setSolvedByUser();
}
}
/**
* If user shows solution, change background color to blue
*/
public void setSolvedBySystem() {
if (isPartOfWord && !isSolved)
this.setBackground(Color.blue);
}
/**
* If user finds word, change background color to green
*/
public void setSolvedByUser() {
this.setBackground(Color.green);
this.isSolved = true;
}
}