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
| /*
*******************************************
* *
* Kalender.java *
* Gemaakt door Roel van Nuland *
* GoT id: Windoos-Vernieler *
* *
*******************************************
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
public class Kalender extends JDialog implements WindowListener, ActionListener
{
Insets Dagen = new Insets(1,1,1,1);
JButton OKButton = new JButton("OK");
JButton CancelButton = new JButton("Annuleren");
JButton VolMaandButton = new JButton(">");
JButton VolJaarButton = new JButton(">>");
JButton VorMaandButton = new JButton("<");
JButton VorJaarButton = new JButton("<<");
JLabel MaandLabel = new JLabel();
String[] DagNaam = new String[7];
String[] MaandNaam = new String[12];
JLabel[] DagLabel = new JLabel[7];
JButton[] Dag = new JButton[61];
JButton[] Leeg = new JButton[14];
JLabel[] WeekLabel = new JLabel[7];
Calendar Kal = new GregorianCalendar();
Calendar Kal2 = new GregorianCalendar();
Color geselecteerd = new Color(255,255,255);
int DagSelectie = 0;
boolean datumGeven = false;
public final static int YES = 1;
public final static int NO = 0;
public int[] ShowNow(Color nieuw)
{
geselecteerd=nieuw;
this.show();
int[] geefterug = new int[4];
if (datumGeven)
{
geefterug[0]=1;
geefterug[1]=Kal.get(Calendar.YEAR);
geefterug[2]=Kal.get(Calendar.MONTH);
geefterug[3]=Kal.get(Calendar.DAY_OF_MONTH);
}
else
geefterug[0]=0;
return (geefterug);
}
public void maakveld()
{
this.getContentPane().removeAll();
this.getContentPane().add(OKButton);
this.getContentPane().add(CancelButton);
this.getContentPane().add(VorMaandButton);
this.getContentPane().add(VorJaarButton);
this.getContentPane().add(VolMaandButton);
this.getContentPane().add(VolJaarButton);
int i,j,x,y,breed,lang,teldag,telweek,aantaldagen,leegvoor,telleeg;
x=80;
y=15;
breed=25;
lang=25;
teldag=0;
telweek=30;
leegvoor=6;
telleeg=0;
aantaldagen=Kal.getActualMaximum(Calendar.DAY_OF_MONTH);
DagSelectie=Kal.get(Calendar.DAY_OF_MONTH)-1;
Kal.set(Calendar.DAY_OF_MONTH,1);
telweek=Kal.get(Calendar.WEEK_OF_YEAR);
leegvoor=Kal.get(Calendar.DAY_OF_WEEK)-1;
MaandLabel.setText(MaandNaam[Kal.get(Calendar.MONTH)]+" "+Kal.get(Calendar.YEAR));
MaandLabel.setHorizontalAlignment(JLabel.CENTER);
this.getContentPane().add(MaandLabel);
MaandLabel.setBounds(x,y,breed*6,lang);
MaandLabel.setFont(new Font("Dialog",1,18));
y=y+lang;
for (i=0;i<7;i=i+1)
{
DagLabel[i] = new JLabel(DagNaam[i]);
this.getContentPane().add(DagLabel[i]);
DagLabel[i].setBounds(x,y,breed,lang);
DagLabel[i].setHorizontalAlignment(JLabel.CENTER);
x=x+breed;
}
x=x-(breed*8);
y=y+lang;
for (i=0;i<6;i=i+1)
{
if (telweek>52)
{
telweek=1;
}
WeekLabel[i] = new JLabel(Integer.toString(telweek));
this.getContentPane().add(WeekLabel[i]);
WeekLabel[i].setBounds(x,y,breed,lang);
WeekLabel[i].setHorizontalAlignment(JLabel.CENTER);
telweek=telweek+1;
x=x+breed;
for (j=0;j<7;j=j+1)
{
if (leegvoor>0)
{
Leeg[telleeg] = new JButton();
this.getContentPane().add(Leeg[telleeg]);
Leeg[telleeg].setBounds(x,y,breed,lang);
Leeg[telleeg].addActionListener(this);
telleeg=telleeg+1;
leegvoor=leegvoor-1;
}
else
{
if (aantaldagen>teldag)
{
Dag[teldag] = new JButton(Integer.toString(teldag+1));
this.getContentPane().add(Dag[teldag]);
Dag[teldag].setBounds(x,y,breed,lang);
Dag[teldag].setMargin(new Insets(1,1,1,1));
Dag[teldag].addActionListener(this);
teldag=teldag+1;
}
else
{
Leeg[telleeg] = new JButton();
this.getContentPane().add(Leeg[telleeg]);
Leeg[telleeg].setBounds(x,y,breed,lang);
Leeg[telleeg].addActionListener(this);
telleeg=telleeg+1;
}
}
x=x+breed;
}
x=x-(breed*8);
y=y+lang;
}
Dag[DagSelectie].setBackground(geselecteerd);
Kal.set(Calendar.DAY_OF_MONTH,DagSelectie+1);
if (Kal.get(Calendar.YEAR)==Kal2.get(Calendar.YEAR) && Kal.get(Calendar.MONTH)==Kal2.get(Calendar.MONTH))
Dag[Kal2.get(Calendar.DAY_OF_MONTH)-1].setBackground(Color.white);
}
public void StartKalender()
{
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
this.getContentPane().setLayout(null);
this.setResizable(true);
this.setTitle("Kalender");
this.setSize(325,290);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = this.getSize();
if (frameSize.height > screenSize.height)
frameSize.height = screenSize.height;
if (frameSize.width > screenSize.width)
frameSize.width = screenSize.width;
this.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
OKButton.setBounds(53,230,95,23);
this.getContentPane().add(OKButton);
OKButton.addActionListener(this);
CancelButton.setBounds(158,230,95,23);
this.getContentPane().add(CancelButton);
CancelButton.addActionListener(this);
VorMaandButton.setBounds(15,115,35,25);
this.getContentPane().add(VorMaandButton);
VorMaandButton.addActionListener(this);
VorMaandButton.setMargin(new Insets(1,1,1,1));
VorJaarButton.setBounds(15,140,35,25);
this.getContentPane().add(VorJaarButton);
VorJaarButton.addActionListener(this);
VorJaarButton.setMargin(new Insets(1,1,1,1));
VolMaandButton.setBounds(265,115,35,25);
this.getContentPane().add(VolMaandButton);
VolMaandButton.addActionListener(this);
VolMaandButton.setMargin(new Insets(1,1,1,1));
VolJaarButton.setBounds(265,140,35,25);
this.getContentPane().add(VolJaarButton);
VolJaarButton.addActionListener(this);
VolJaarButton.setMargin(new Insets(1,1,1,1));
DagNaam[0] = new String("Zo");
DagNaam[1] = new String("Ma");
DagNaam[2] = new String("Di");
DagNaam[3] = new String("Wo");
DagNaam[4] = new String("Do");
DagNaam[5] = new String("Vr");
DagNaam[6] = new String("Za");
MaandNaam[0] = new String("Januari");
MaandNaam[1] = new String("Februarie");
MaandNaam[2] = new String("Maart");
MaandNaam[3] = new String("April");
MaandNaam[4] = new String("Mei");
MaandNaam[5] = new String("Juni");
MaandNaam[6] = new String("Juli");
MaandNaam[7] = new String("Augustus");
MaandNaam[8] = new String("September");
MaandNaam[9] = new String("Oktober");
MaandNaam[10] = new String("November");
MaandNaam[11] = new String("December");
maakveld();
}
public Kalender(Frame parent)
{
super(parent,true);
StartKalender();
}
public Kalender(Dialog parent)
{
super(parent,true);
StartKalender();
}
public void actionPerformed(ActionEvent aEvent)
{
if (aEvent.getSource() == OKButton)
{
datumGeven=true;
dispose();
}
if (aEvent.getSource() == CancelButton)
{
dispose();
}
for (int i=0;i<31;i=i+1)
{
if (aEvent.getSource() == Dag[i])
{
Dag[DagSelectie].setBackground(Color.lightGray);
Dag[i].setBackground(geselecteerd);
DagSelectie=i;
Kal.set(Calendar.DAY_OF_MONTH,DagSelectie+1);
Dag[DagSelectie].setForeground(Color.black);
if (geselecteerd.getRed()+geselecteerd.getGreen()+geselecteerd.getBlue()<382)
{
Dag[DagSelectie].setForeground(Color.white);
}
if (Kal.get(Calendar.YEAR)==Kal2.get(Calendar.YEAR) && Kal.get(Calendar.MONTH)==Kal2.get(Calendar.MONTH))
{
Dag[Kal2.get(Calendar.DAY_OF_MONTH)-1].setBackground(Color.white);
Dag[Kal2.get(Calendar.DAY_OF_MONTH)-1].setForeground(Color.black);
}
}
}
if (aEvent.getSource() == VorMaandButton)
{
int i = Kal.get(Calendar.MONTH);
if (i==1)
{
Kal.set(Calendar.MONTH,12);
Kal.set(Calendar.YEAR,Kal.get(Calendar.YEAR)-1);
}
else
{
Kal.set(Calendar.MONTH,i-1);
}
maakveld();
}
if (aEvent.getSource() == VorJaarButton)
{
Kal.set(Calendar.YEAR,Kal.get(Calendar.YEAR)-1);
maakveld();
}
if (aEvent.getSource() == VolMaandButton)
{
int i = Kal.get(Calendar.MONTH);
if (i==12)
{
Kal.set(Calendar.MONTH,1);
Kal.set(Calendar.YEAR,Kal.get(Calendar.YEAR)+1);
}
else
{
Kal.set(Calendar.MONTH,i+1);
}
maakveld();
}
if (aEvent.getSource() == VolJaarButton)
{
Kal.set(Calendar.YEAR,Kal.get(Calendar.YEAR)+1);
maakveld();
}
}
public void windowClosing(WindowEvent win_event)
{
dispose();
}
public void windowClosed(WindowEvent win_event) {}
public void windowIconified(WindowEvent win_event) {}
public void windowOpened(WindowEvent win_event) {}
public void windowDeiconified(WindowEvent win_event) {}
public void windowActivated(WindowEvent win_event) {}
public void windowDeactivated(WindowEvent win_event) {}
} |