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;
}
}
|
W= (d+2*m+3*(m+1)/5+y+y/4-y/100+y/400) mod 7
m 月
y 年
1月2月换算为去年的13 14月计算
w=0是星期一,依次类推。