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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
| import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
class But extends Button implements ActionListener{
Color cr = Color.red;
Color cw = Color.white;
Color cb = Color.black;
But(String label){
super(label);
setSize(10,10);
setBackground(cw);
setForeground(cb);
addActionListener(this);
}
public void actionPerformed(ActionEvent ae){
if(getLabel().equals(" "))return;
if(getBackground().equals(cr)){
setBackground(cw);
setForeground(cb);
}
else{
setBackground(cr);
setForeground(cw);
}
}
}
class EmptyCheckboxPan extends Panel{
CheckBoxPane cbp = new CheckBoxPane();
EmptyCheckboxPan(){
setLayout(null);
setSize(95, 285);
setBackground(Color.darkGray);
setLocation(5, 5);
setVisible(true);
add(cbp);
}
CheckBoxPane getCheckBoxPane(){
return cbp;
}
}
class CheckBoxPane extends Panel{
Checkbox[] cb = new Checkbox[2];
CheckboxGroup cbg = new CheckboxGroup();
String[] label = {"Holidays ", "Working days "};
CheckBoxPane(){
setLayout(null);
setSize(95, 285);
setBackground(Color.darkGray);
setLocation(0, 0);
setVisible(true);
for(int i = 0, k = 90; i < label.length; i++, k = k + 50){
cb[i] = new Checkbox(label[i], cbg, false);
cb[i].setBackground(Color.darkGray);
cb[i].setForeground(Color.white);
cb[i].setSize(90,50);
cb[i].setLocation(3, k);
add(cb[i]);
}
}
}
class EditButton extends Button implements ActionListener{
//CheckBoxPane butpan;
int b;
Color cr = Color.red;
CalendarPanel calpan;
But[][] refBut;
EditButton(But[][] b){
super();
refBut = b;
//butpan = bp;
setLabel("E d i t");
setSize(50,30);
setLocation(25,105);
setBackground(Color.LIGHT_GRAY);
//addActionListener(this);
ActionListener actionlistener = new ButtonsListener();
addActionListener(actionlistener);
}
public void actionPerformed(ActionEvent ae){
//butpan.setVisible(true);
}
public class ButtonsListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
//refBut = calpan.getBut();
for(int i = 0; i < refBut.length; i++){
for(int j = 0; j < 6; j++)
refBut[i][j].setEnabled(true);
}
}
}
}
class OKButton extends Button implements ActionListener{
CheckBoxPane bp;
OKButton(CheckBoxPane bp){
super();
this.bp = bp;
setLabel("O K");
setLocation(25,150);
setSize(50,30);
setBackground(Color.LIGHT_GRAY);
addActionListener(this);
}
public void actionPerformed(ActionEvent ae){
//bp.setVisible(false);
}
}
class ButtonsPane extends Panel{
EditButton eb;
OKButton okb;
But[][] refBut = new But[7][6];
ButtonsPane(EmptyCheckboxPan ecp){
super();
setLayout(null);
setBackground(Color.darkGray);
setSize(100, 285);
setLocation(880, 5);
eb = new EditButton(refBut);
//eb = new EditButton(ecp.getCheckBoxPane());
okb = new OKButton(ecp.getCheckBoxPane());
add(eb);
add(okb);
}
}
class DaysPane{
String[] name = {"Mon","Tue","Wed","Thu","Fri","Sat","Sun"};
Panel p = new Panel();
Button[] refBut = new Button[name.length];
int setx, sety;
DaysPane(int x, int y){
super();
setx = x;
sety = y;
p.setLayout(null);
p.setBackground(Color.gray);
p.setSize(50, 250);
p.setLocation(setx, sety);
for(int i = 0, k = 5; i < name.length; i++, k += 35){
refBut[i] = new Button(name[i]);
refBut[i].setSize(40,30);
refBut[i].setLocation(5,k);
refBut[i].setBackground(Color.white);
p.add(refBut[i]);
}
}
Panel getDaysPane(){
return p;
}
}
class DaysLabel{
Label days = new Label("Days", Label.CENTER);
int setx, sety;
Font font = new Font("Verdana", Font.BOLD, 16);
DaysLabel(int x, int y){
super();
setx = x;
sety = y;
days.setBackground(Color.gray);
days.setFont(font);
days.setLocation(setx, sety);
days.setSize(new Dimension(50, 30));
}
Label getDaysLabel(){
return days;
}
}
class CalendarPanel{
int col;
int dayOfMonth = 0;
int k = 0;
int year;
String monthName;
But[][] b;
JPanel pan = new JPanel();
GregorianCalendar greg;
CalendarPanel(JPanel p, int y, String month){
super();
pan = p;
year = y;
monthName = month;
if(monthName == "September"){
greg = new GregorianCalendar(year,8,1);
k = greg.get(Calendar.DAY_OF_WEEK);
dayOfMonth = greg.getActualMaximum(Calendar.DAY_OF_MONTH);
}
if(monthName == "October"){
greg = new GregorianCalendar(year,9,1);
k = greg.get(Calendar.DAY_OF_WEEK);
dayOfMonth = greg.getActualMaximum(Calendar.DAY_OF_MONTH);
}
if(monthName == "November"){
greg = new GregorianCalendar(year,10,1);
k = greg.get(Calendar.DAY_OF_WEEK);
dayOfMonth = greg.getActualMaximum(Calendar.DAY_OF_MONTH);
}
if(monthName == "December"){
greg = new GregorianCalendar(year,11,1);
k = greg.get(Calendar.DAY_OF_WEEK);
dayOfMonth = greg.getActualMaximum(Calendar.DAY_OF_MONTH);
}
if(monthName == "January"){
greg = new GregorianCalendar(year+1,0,1);
k = greg.get(Calendar.DAY_OF_WEEK);
dayOfMonth = greg.getActualMaximum(Calendar.DAY_OF_MONTH);
}
if(monthName == "February"){
greg = new GregorianCalendar(year+1,1,1);
k = greg.get(Calendar.DAY_OF_WEEK);
dayOfMonth = greg.getActualMaximum(Calendar.DAY_OF_MONTH);
}
if(monthName == "March"){
greg = new GregorianCalendar(year+1,2,1);
k = greg.get(Calendar.DAY_OF_WEEK);
dayOfMonth = greg.getActualMaximum(Calendar.DAY_OF_MONTH);
}
if(monthName == "April"){
greg = new GregorianCalendar(year+1,3,1);
k = greg.get(Calendar.DAY_OF_WEEK);
dayOfMonth = greg.getActualMaximum(Calendar.DAY_OF_MONTH);
}
if(monthName == "May"){
greg = new GregorianCalendar(year+1,4,1);
k = greg.get(Calendar.DAY_OF_WEEK);
dayOfMonth = greg.getActualMaximum(Calendar.DAY_OF_MONTH);
}
//calendar, 31 days
//dates
int[] d = new int[dayOfMonth+1];
for(int i = 1; i < d.length; i++)
d[i] = i;
//determine the day of the week in range 0-7
if(k == 1)
k = 6;
else
k -= 2;
//formation of the blank calendar
int col;
col = k <= 4?5:6;
b = new But[7][col];
for(int i = 0; i < b.length; i++)
for(int j = 0; j < col; j++)
b[i][j] = new But(" ");
//set the days of the week in the panel
pan.setBackground(Color.gray);
pan.setBorder(new EmptyBorder(5,5,5,5));
pan.setLayout(new GridLayout(7,col+1,5,5));
for(int i = 0; i < b.length; i++){
for(int j = 0; j < col; j++){
b[i][j].setEnabled(false);
pan.add(b[i][j]);
}
}
//create the calendar
int n;
n = 1;
for(int j = 0; j < col; j++)
for(int i = j == 0?k:0; (i < b.length) && (n < d.length); i++){
b[i][j].setLabel("" + d[n++]);
}
//Mark the Saturdays and Sundays
for(int i = 5; i < 7; i++)
for(int j = 0; j < col; j++){
if(b[i][j].getLabel().equals(" "))
b[i][j].setBackground(Color.lightGray);
else{
b[i][j].setBackground(Color.red);
b[i][j].setForeground(Color.white);
}
}
}
JPanel getPanel(){
return pan;
}
But[][] getBut(){
return b;
}
}
public class ColorButton {
private static void createAndShowGUI(){
CalendarPanel cp1;
CalendarPanel cp2;
Frame f = new Frame("Teacher's Calendar");
f.setBackground(Color.lightGray);
f.setSize(991,613);
f.setResizable(false);
f.setLayout(new GridLayout(2,1,5,5));
//close the application
f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent we){
System.exit(0);
}
});
Panel TopPanel = new Panel();
TopPanel.setBackground(Color.lightGray);
TopPanel.setLayout(null);
Panel BottomPanel = new Panel();
BottomPanel.setBackground(Color.lightGray);
BottomPanel.setLayout(null);
f.add(TopPanel);
f.add(BottomPanel);
//add a empty darkgray panel
EmptyCheckboxPan eckbp = new EmptyCheckboxPan();
TopPanel.add(eckbp);
//add a buttons panel
ButtonsPane buttons = new ButtonsPane(eckbp);
TopPanel.add(buttons);
//add a days button top panel
DaysPane topdays = new DaysPane(105,40);
TopPanel.add(topdays.getDaysPane());
//add a days button bottom panel
DaysPane bottomdays = new DaysPane(5,35);
BottomPanel.add(bottomdays.getDaysPane());
//add a top label DAYS
DaysLabel days = new DaysLabel(105, 5);
TopPanel.add(days.getDaysLabel());
//add a bottom label DAYS
DaysLabel days1 = new DaysLabel(5, 0);
BottomPanel.add(days1.getDaysLabel());
String[] mName1 = {"September","October","November","December"};
Label[] lab = new Label[mName1.length];
Font font = new Font("Verdana", Font.BOLD, 16);
for(int i = 0, k = 160; i < lab.length; i++, k = k + 180){
lab[i] = new Label(mName1[i], Label.CENTER);
lab[i].setBackground(Color.gray);
lab[i].setFont(font);
lab[i].setLocation(k, 5);
lab[i].setSize(new Dimension(175, 30));
TopPanel.add(lab[i]);
}
JPanel[] calendarPanel1 = new JPanel[4];
for(int i = 0, k = 160; i < calendarPanel1.length; i++, k = k + 180){
calendarPanel1[i] = new JPanel();
cp1 = new CalendarPanel(calendarPanel1[i], 2015, mName1[i]);
calendarPanel1[i] = cp1.getPanel();
calendarPanel1[i].setLocation(k, 40);
calendarPanel1[i].setSize(new Dimension(175, 250));
TopPanel.add(calendarPanel1[i]);
}
String[] mName2 = {"January","February","March","April","May"};
Label[] lab2 = new Label[mName2.length];
for(int i = 0, k = 60; i < lab2.length; i++, k = k + 185){
lab2[i] = new Label(mName2[i], Label.CENTER);
lab2[i].setBackground(Color.gray);
lab2[i].setFont(font);
lab2[i].setLocation(k, 0);
lab2[i].setSize(new Dimension(180, 30));
BottomPanel.add(lab2[i]);
}
JPanel[] calendarPanel2 = new JPanel[5];
for(int i = 0, k = 60; i < calendarPanel2.length; i++, k = k + 185){
calendarPanel2[i] = new JPanel();
cp2 = new CalendarPanel(calendarPanel2[i], 2015, mName2[i]);
calendarPanel2[i] = cp2.getPanel();
calendarPanel2[i].setLocation(k, 35);
calendarPanel2[i].setSize(new Dimension(180, 250));
BottomPanel.add(calendarPanel2[i]);
}
f.setLocation(50,50);
f.setVisible(true);
}
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
} |