学习的榜样!

知识改变命运!!!
[/url]
程序代码: private class JP1 extends JPanel{
JLabel lastYear,nextYear,lastMonth,nextMonth,center;
public JP1(){
//super(new BorderLayout());
this.setBackground(new Color(160,185,215));
initJP1();
}
private void initJP1(){
lastYear=new JLabel(" << ",JLabel.CENTER);
nextYear=new JLabel(" >> ",JLabel.CENTER);
lastYear.setToolTipText("上一年");
nextYear.setToolTipText("下一年");
lastMonth=new JLabel(" < ",JLabel.CENTER);
lastMonth.setToolTipText("上一月");
nextMonth=new JLabel(" > ",JLabel.CENTER);
nextMonth.setToolTipText("下一月");
center=new JLabel("",JLabel.CENTER);
updateDate();
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
this.setLayout(gridbag);
c.weightx=0.5;
gridbag.setConstraints(lastYear, c);
this.add(lastYear);
c.weightx=0.5;
gridbag.setConstraints(lastMonth, c);
this.add(lastMonth);
c.weightx=8.0;
gridbag.setConstraints(center, c);
this.add(center);
c.weightx=0.5;
gridbag.setConstraints(nextMonth, c);
this.add(nextMonth);
c.weightx=0.5;
gridbag.setConstraints(nextYear, c);
this.add(nextYear);
//this.add(left,BorderLayout.WEST);
//this.add(center,BorderLayout.CENTER);
//this.add(right,BorderLayout.EAST);
this.setPreferredSize(new Dimension(295,25));
lastYear.addMouseListener(new MouseAdapter(){
public void mouseEntered(MouseEvent me){
lastYear.setCursor(new Cursor(Cursor.HAND_CURSOR));
lastYear.setForeground(Color.RED);
}
public void mouseExited(MouseEvent me){
lastYear.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
lastYear.setForeground(Color.BLACK);
}
public void mousePressed(MouseEvent me){
select.add(Calendar.YEAR,-1);
lastYear.setForeground(Color.WHITE);
refresh();
}
public void mouseReleased(MouseEvent me){
lastYear.setForeground(Color.BLACK);
}
});
nextYear.addMouseListener(new MouseAdapter(){
public void mouseEntered(MouseEvent me){
nextYear.setCursor(new Cursor(Cursor.HAND_CURSOR));
nextYear.setForeground(Color.RED);
}
public void mouseExited(MouseEvent me){
nextYear.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
nextYear.setForeground(Color.BLACK);
}
public void mousePressed(MouseEvent me){
select.add(Calendar.YEAR,1);
nextYear.setForeground(Color.WHITE);
refresh();
}
public void mouseReleased(MouseEvent me){
nextYear.setForeground(Color.BLACK);
}
});
lastMonth.addMouseListener(new MouseAdapter(){
public void mouseEntered(MouseEvent me){
lastMonth.setCursor(new Cursor(Cursor.HAND_CURSOR));
lastMonth.setForeground(Color.RED);
}
public void mouseExited(MouseEvent me){
lastMonth.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
lastMonth.setForeground(Color.BLACK);
}
public void mousePressed(MouseEvent me){
select.add(Calendar.MONTH,-1);
lastMonth.setForeground(Color.WHITE);
refresh();
}
public void mouseReleased(MouseEvent me){
lastMonth.setForeground(Color.BLACK);
}
});
nextMonth.addMouseListener(new MouseAdapter(){
public void mouseEntered(MouseEvent me){
nextMonth.setCursor(new Cursor(Cursor.HAND_CURSOR));
nextMonth.setForeground(Color.RED);
}
public void mouseExited(MouseEvent me){
nextMonth.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
nextMonth.setForeground(Color.BLACK);
}
public void mousePressed(MouseEvent me){
select.add(Calendar.MONTH,1);
nextMonth.setForeground(Color.WHITE);
refresh();
}
public void mouseReleased(MouseEvent me){
nextMonth.setForeground(Color.BLACK);
}
});
}
private void updateDate(){
center.setText(select.get(Calendar.YEAR)+"年"+(select.get(Calendar.MONTH)+1)+"月");
}
}

