求助!匿名类中的鼠标事件无响应?在线等!!!感谢了
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;
GregorianCalendar d = new GregorianCalendar();
GregorianCalendar day = new GregorianCalendar();
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]);
}
for(JLabel l:label){
//鼠标效果
l.addMouseListener(new MouseListener(){
public void mousePressed(MouseEvent event){}
public void mouseClicked(MouseEvent event){}
public void mouseExited(MouseEvent event){}
public void mouseEntered(MouseEvent event){}
public void mouseReleased(MouseEvent event){}
});
l.addMouseMotionListener(new MouseMotionListener(){
public void mouseMoved(MouseEvent event){
setBackground(Color.BLUE);
}
public void mouseDragged(MouseEvent event){
}
});
}
}
// 日期表格容器结束;
printcalendar();
}
// 输出日期表
private 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(today);
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++;