这是个日历程序,我想通过选择月份改变每月的日历.为什么选择却没有效果呢?
package Calendar;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
class Calendarday extends JPanel {
private JPanel dayPanel;
private static int count = 0;
private JLabel[] label;
private static final GregorianCalendar d = new GregorianCalendar();
private static final GregorianCalendar day = new GregorianCalendar();
public void setMonth(int month){
d.set(Calendar.MONTH, month-1);
day.set(Calendar.MONTH, month-1);
System.out.println(d.get(Calendar.MONTH));
}
public void setYear(int year){
d.set(Calendar.YEAR, year);
day.set(Calendar.YEAR, year);
}
public Calendarday() {
// 日期容器开始:
day.set(Calendar.DAY_OF_MONTH, 1);
int weekday = day.get(Calendar.DAY_OF_WEEK);
dayPanel = new JPanel();
// 根据每月的第一天来判断,决定日期表格容器的大小:
if (weekday == 7 || weekday==6) {
dayPanel.setLayout(new GridLayout(6, 7));
label = new JLabel[42];
for (int i = 0; i < label.length; i++) {
label[i] = new JLabel( " ");
dayPanel.add(label[i]);
}
} else {
dayPanel.setLayout(new GridLayout(5, 7));
label = new JLabel[35];
for (int i = 0; i < label.length; i++) {
label[i] = new JLabel( " ");
dayPanel.add(label[i]);
label[i].addMouseListener(new mousel());
}
}
// 日期表格容器结束;
printcalendar();
}
// 输出日期表
public void printcalendar() {
int today = d.get(Calendar.DAY_OF_MONTH);
int month = d.get(Calendar.MONTH);
d.set(Calendar.DAY_OF_MONTH, 1);
int weekday = d.get(Calendar.DAY_OF_WEEK);
for (int i = Calendar.SUNDAY; i < weekday; i++) {
label[count].setText( " ");
count++;
}
System.out.println(month+ "ss ");
do {
int day = d.get(Calendar.DAY_OF_MONTH);
label[count].setText(Integer.toString(day));
if (day == today) {
label[count].setText(label[count].getText() + "* ");
} else {
label[count].setText(label[count].getText() + " ");
}
d.add(Calendar.DAY_OF_MONTH, 1);
weekday = d.get(Calendar.DAY_OF_WEEK);
count++;
} while (d.get(Calendar.MONTH) == month);
count=0;
}
private class mousel extends MouseAdapter{
public void mousePressed(MouseEvent event){}
public void mouseClicked(MouseEvent event){}