-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdigitaldisplay.java
More file actions
243 lines (198 loc) · 6.16 KB
/
digitaldisplay.java
File metadata and controls
243 lines (198 loc) · 6.16 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
/*
DigitalDisplay class implements a digital display
costructor: digitaldisplay(boolean true/false for a big display or not
int number of digits (max MAXNUMCIFRE)
Color display background color
Color display foreground color)
methods: void SetValue(String value to display)
written by:
umbio
Messina (Italy)
"Thanks to Kazuma's kzmClock applet"
*/
import java.awt.*;
import java.util.*;
public class digitaldisplay extends Canvas {
int VerLedx[], VerLedy[], HorLedx[], HorLedy[];
int CifraXP, CifraYP; // x,y position of all the numbers
int CifraVal[]; // used for displaying
boolean BigClock; // is the clock big ?
String Led[]; // status of leds
String Cifre[]; // structure of all the 10 numbers
Color bgColor; // background color
Color fgColor; // foreground color
String strValueDisplayed;
int NumCifre;
static int MAXNUMCIFRE=10;
// constructor //
public digitaldisplay(boolean BigClock, int NumCifre, Color bgColor, Color fgColor) {
this.BigClock=BigClock;
this.NumCifre=NumCifre;
this.bgColor=bgColor;
this.fgColor=fgColor;
CifraVal=new int[MAXNUMCIFRE];
if (BigClock == true) {
VerLedx = getParameterIntList("2 3 5 5 3 2 0 0 2", ' ');
VerLedy = getParameterIntList("0 0 2 17 19 19 17 2 0", ' ');
HorLedx = getParameterIntList("2 17 19 19 17 2 0 0 2", ' ');
HorLedy = getParameterIntList("0 0 2 3 5 5 3 2 0", ' ');
Led = getParameterList("H 4 0,V 0 4,V 22 4,H 4 22,V 0 26,V 22 26,H 4 44", ',');
CifraYP = 5;
CifraXP = 37;
resize(new Dimension(CifraXP*NumCifre, 60));
} else {
VerLedx = getParameterIntList("0 1 2 3 3 2 1 0 0", ' ');
VerLedy = getParameterIntList("1 0 0 1 8 9 9 8 1", ' ');
HorLedx = getParameterIntList("0 1 8 9 9 8 1 0 0", ' ');
HorLedy = getParameterIntList("1 0 0 1 2 2 3 2 1", ' ');
Led = getParameterList("H 3 0,V 0 3,V 12 3,H 3 12,V 0 15,V 12 15,H 3 24", ',');
CifraYP = 3;
CifraXP = 20;
resize(new Dimension(CifraXP*NumCifre-CifraYP, 32));
}
Cifre = new String[10];
Cifre[0] = "1 1 1 0 1 1 1";
Cifre[1] = "0 0 1 0 0 1 0";
Cifre[2] = "1 0 1 1 1 0 1";
Cifre[3] = "1 0 1 1 0 1 1";
Cifre[4] = "0 1 1 1 0 1 0";
Cifre[5] = "1 1 0 1 0 1 1";
Cifre[6] = "0 1 0 1 1 1 1";
Cifre[7] = "1 0 1 0 0 1 0";
Cifre[8] = "1 1 1 1 1 1 1";
Cifre[9] = "1 1 1 1 0 1 0";
} // end of constructor
public void SetValue(String str) {
for (int i=0;i<MAXNUMCIFRE-1;i++){ CifraVal[i]=0; }
for (int i=0;i<str.length();i++){
CifraVal[NumCifre-str.length()+i]=Integer.parseInt(str.substring(i,i+1));
}
strValueDisplayed=str;
repaint();
}
//
// getParameterList
// (read a multiple parameter string and
// separated by a definible char and return
// a string list containing parameters)
//
String[] getParameterList(String param, char sep) {
String p = param;
String[] result = null;
if (param != null) {
int pos = 0;
int count = 0;
while ((pos = p.indexOf(sep)) >= 0) {
p = p.substring(pos + 1);
count++;
}
if (p.length() > 0) {
count++;
}
result = new String[count];
p = param;
for (int i=0; i<result.length; i++) {
pos = p.indexOf(sep);
if (pos < 0) {
result[i] = p.substring(0, p.length());
p = null;
} else {
result[i] = p.substring(0, pos);
p = p.substring(pos+1);
}
}
}
return result;
}// end of getParameterList
//
// getParameterIntList
// (read a multiple parameter string and
// separated by a definible char and return
// a int list containing parameters)
//
int[] getParameterIntList(String param, char sep) {
String p = param;
int[] result = null;
if (param != null) {
int pos = 0;
int count = 0;
while ((pos = p.indexOf(sep)) >= 0) {
p = p.substring(pos + 1);
count++;
}
if (p.length() > 0) {
count++;
}
result = new int[count];
p = param;
for (int i=0; i<result.length; i++) {
pos = p.indexOf(sep);
if (pos < 0) {
result[i] = Integer.parseInt(p.substring(0, p.length()));
p = null;
} else {
result[i] = Integer.parseInt(p.substring(0, pos));
p = p.substring(pos+1);
}
}
}
return result;
}// end of getParameterIntList
//
// PrintLed (print a led of a number)
//
// Input: graphic (Graphics),the led number (int),x (int),y (int),color (Color)
public void PrintLed(Graphics g, int TheLed, int x, int y, Color TheColor) {
String pTemp[];
int DrawLedx[],
DrawLedy[];
DrawLedx = new int[9];
DrawLedy = new int[9];
pTemp = getParameterList(Led[TheLed],' ');
if (pTemp[0].compareTo("H") == 0) {
for (int j=0; j<=8; j++) {
DrawLedx[j] = 0;
DrawLedy[j] = 0;
DrawLedx[j] = HorLedx[j] + x + Integer.parseInt(pTemp[1]);
DrawLedy[j] = HorLedy[j] + y + Integer.parseInt(pTemp[2]);
}
} else {
for (int j=0; j<=8; j++) {
DrawLedx[j] = 0;
DrawLedy[j] = 0;
DrawLedx[j] = VerLedx[j] + x + Integer.parseInt(pTemp[1]);
DrawLedy[j] = VerLedy[j] + y + Integer.parseInt(pTemp[2]);
}
}
g.setColor(TheColor);
g.fillPolygon(DrawLedx, DrawLedy, 9);
}// end of PrintLed
//
// PrintCifra (print a number)
//
// Input: graphic (Graphics),the number (int),x (int),y (int)
public void PrintCifra(Graphics g, int LaCifra, int xpos, int ypos) {
String CT[];
CT = getParameterList(Cifre[LaCifra], ' ');
for (int i=0; i<=6; i++) {
if (CT[i].compareTo("1") == 0) {
PrintLed(g, i, xpos, ypos, fgColor);
} else {
PrintLed(g, i, xpos, ypos, bgColor);
}
}
}// end of PrintCifra
// Paint
//
public void paint(Graphics g) {
g.setColor(bgColor);
g.fillRect(0,0,size().width, size().height);
g.setColor(fgColor);
for (int i=0; i<NumCifre; i++) {
PrintCifra(g, CifraVal[i], CifraXP*i, CifraYP);
}
}
// Update
//
public void update(Graphics g) { paint(g); }
} // end of class