public
class
CalendarViewer
extends
JWindow
implements
ActionListener {
JPanel
calendarYmPanel
=
null
;
JButton
leftButton
=
new
JButton(
"<<"
);
JButton
rightButton
=
new
JButton(
">>"
);
Label
yearLabel
=
new
Label();
Label
monthLabel
=
new
Label();
Label
passedDaysLabel
=
new
Label();
JPanel
calendarWdPanel
=
null
;
//
是
caledar_week
和
calendar_days
的總包容體
JPanel
calendarWeekPanel
=
null
;
//
針對周列的佈局
JPanel
calendarDaysPanel
=
null
;
//
針對日期列的佈局
JPanel
calendarExitPanel
=
null
;
JButton
quitButton
=
new
JButton(
"
關閉
"
);
Border
emptyBorder
= BorderFactory.createEmptyBorder();
CalendarController
cController
=
new
CalendarController();
public
CalendarViewer() {
super
();
buildUI();
}
public
void
buildUI() {
buildTopPanel();
buildCenterPanel();
buildBottomPanel();
setLayout(
new
BorderLayout());
。。。。。。
}
private
void
buildTopPanel() {
。。。。。。
}
private
void
buildCenterPanel() {
。。。。。。
}
private
void
buildBottomPanel() {
。。。。。。
}
public
JPanel updateDaysPanel() {
。。。。。。
}
public
void
updatePassedDaysLabel() {
。。。。。。
}
public
void
actionPerformed(ActionEvent e) {
。。。。。。
}
public
static
void
main(String[] args) {
SwingUtilities.invokeLater(
new
Runnable() {
public
void
run() {
new
CalendarViewer();
}
});
}
}
|
public
class
CalendarModel {
private
int
daytab
[][] = {
{ 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
{ 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } };
public
boolean
isLeapYear(
int
year) {
return
((year % 4 == 0 && year % 100 != 0) || year % 400 == 0);
}
public
int
dayOfYear(
int
day,
int
month,
int
year) {
int
leap = isLeapYear(year) ? 1 : 0;
for
(
int
i = 1; i < month; i++)
day +=
daytab
[leap][i];
return
day;
}
public
int
daysOfMonth(
int
month,
int
year) {
int
leap = isLeapYear(year) ? 1 : 0;
return
daytab
[leap][month];
}
public
int
dayOfWeek(
int
day,
int
month,
int
year) {
if
(month == 1) {
month = 13;
year--;
}
if
(month == 2) {
month = 14;
year--;
}
return
(day + 2 * month + 3 * (month + 1) / 5 + year + year / 4 - year
/ 100 + year / 400) % 7 + 1;
}
}
|