是不是要 先作个万年历?不知有不有朋友有这方面的代码,分享一下

解决方案 »

  1.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主【nuerron】截止到2008-07-15 22:58:23的历史汇总数据(不包括此帖):
    发帖的总数量:1                        发帖的总分数:0                        每贴平均分数:0                        
    回帖的总数量:0                        得分贴总数量:0                        回帖的得分率:0%                       
    结贴的总数量:0                        结贴的总分数:0                        
    无满意结贴数:0                        无满意结贴分:0                        
    未结的帖子数:1                        未结的总分数:0                        
    结贴的百分比:0.00  %               结分的百分比:---------------------
    无满意结贴率:---------------------无满意结分率:---------------------
    如何结贴请参考这里:http://topic.csdn.net/u/20080501/09/ef7ba1b3-6466-49f6-9d92-36fe6d471dd1.html
      

  2.   

    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Component;
    import java.awt.Container;
    import java.awt.FlowLayout;
    import java.awt.GridLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.util.Calendar;
    import java.util.GregorianCalendar;import javax.swing.BorderFactory;
    import javax.swing.JButton;
    import javax.swing.JComboBox;
    import javax.swing.JFrame;
    import javax.swing.JPanel;public class Cal extends JPanel {  protected int yy;
      protected int mm, dd;
      protected JButton labs[][];
      protected int leadGap = 0;  Calendar calendar = new GregorianCalendar();  protected final int thisYear = calendar.get(Calendar.YEAR);  protected final int thisMonth = calendar.get(Calendar.MONTH);  private JButton b0;
      private JComboBox monthChoice;
      private JComboBox yearChoice;  Cal() {
        super();
        setYYMMDD(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH),
            calendar.get(Calendar.DAY_OF_MONTH));
        buildGUI();
        recompute();
      }  Cal(int year, int month, int today) {
        super();
        setYYMMDD(year, month, today);
        buildGUI();
        recompute();
      }  private void setYYMMDD(int year, int month, int today) {
        yy = year;
        mm = month;
        dd = today;
      }  String[] months = { "January", "February", "March", "April", "May", "June",
          "July", "August", "September", "October", "November", "December" };  private void buildGUI() {
        getAccessibleContext().setAccessibleDescription(
            "Calendar not accessible yet. Sorry!");
        setBorder(BorderFactory.createEtchedBorder());    setLayout(new BorderLayout());    JPanel tp = new JPanel();
        tp.add(monthChoice = new JComboBox());
        for (int i = 0; i < months.length; i++)
          monthChoice.addItem(months[i]);
        monthChoice.setSelectedItem(months[mm]);
        monthChoice.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent ae) {
            int i = monthChoice.getSelectedIndex();
            if (i >= 0) {
              mm = i;
              recompute();
            }
          }
        });
        monthChoice.getAccessibleContext().setAccessibleName("Months");
        monthChoice.getAccessibleContext().setAccessibleDescription(
            "Choose a month of the year");    tp.add(yearChoice = new JComboBox());
        yearChoice.setEditable(true);
        for (int i = yy - 5; i < yy + 5; i++)
          yearChoice.addItem(Integer.toString(i));
        yearChoice.setSelectedItem(Integer.toString(yy));
        yearChoice.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent ae) {
            int i = yearChoice.getSelectedIndex();
            if (i >= 0) {
              yy = Integer.parseInt(yearChoice.getSelectedItem()
                  .toString());
              recompute();
            }
          }
        });
        add(BorderLayout.CENTER, tp);    JPanel bp = new JPanel();
        bp.setLayout(new GridLayout(7, 7));
        labs = new JButton[6][7]; // first row is days    bp.add(b0 = new JButton("S"));
        bp.add(new JButton("M"));
        bp.add(new JButton("T"));
        bp.add(new JButton("W"));
        bp.add(new JButton("R"));
        bp.add(new JButton("F"));
        bp.add(new JButton("S"));    ActionListener dateSetter = new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            String num = e.getActionCommand();
            if (!num.equals("")) {
              setDayActive(Integer.parseInt(num));
            }
          }
        };
        for (int i = 0; i < 6; i++)
          for (int j = 0; j < 7; j++) {
            bp.add(labs[i][j] = new JButton(""));
            labs[i][j].addActionListener(dateSetter);
          }    add(BorderLayout.SOUTH, bp);
      }  public final static int dom[] = { 31, 28, 31, 30,31, 30, 31, 31,30, 31, 30, 31 };  protected void recompute() {
        if (mm < 0 || mm > 11)
          throw new IllegalArgumentException("Month " + mm
              + " bad, must be 0-11");
        clearDayActive();
        calendar = new GregorianCalendar(yy, mm, dd);    leadGap = new GregorianCalendar(yy, mm, 1).get(Calendar.DAY_OF_WEEK) - 1;    int daysInMonth = dom[mm];
        if (isLeap(calendar.get(Calendar.YEAR)) && mm > 1)
          ++daysInMonth;    for (int i = 0; i < leadGap; i++) {
          labs[0][i].setText("");
        }    for (int i = 1; i <= daysInMonth; i++) {
          JButton b = labs[(leadGap + i - 1) / 7][(leadGap + i - 1) % 7];
          b.setText(Integer.toString(i));
        }    for (int i = leadGap + 1 + daysInMonth; i < 6 * 7; i++) {
          labs[(i) / 7][(i) % 7].setText("");
        }    if (thisYear == yy && mm == thisMonth)
          setDayActive(dd);    repaint();
      }  public boolean isLeap(int year) {
        if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
          return true;
        return false;
      }  public void setDate(int yy, int mm, int dd) {
        this.yy = yy;
        this.mm = mm; // starts at 0, like Date
        this.dd = dd;
        recompute();
      }  private void clearDayActive() {
        JButton b;    if (activeDay > 0) {
          b = labs[(leadGap + activeDay - 1) / 7][(leadGap + activeDay - 1) % 7];
          b.setBackground(b0.getBackground());
          b.repaint();
          activeDay = -1;
        }
      }  private int activeDay = -1;  public void setDayActive(int newDay) {    clearDayActive();    if (newDay <= 0)
          dd = new GregorianCalendar().get(Calendar.DAY_OF_MONTH);
        else
          dd = newDay;
        Component square = labs[(leadGap + newDay - 1) / 7][(leadGap + newDay - 1) % 7];
        square.setBackground(Color.red);
        square.repaint();
        activeDay = newDay;
      }  public static void main(String[] av) {
        JFrame f = new JFrame("Cal");
        Container c = f.getContentPane();
        c.setLayout(new FlowLayout());
        c.add(new Cal(1995, 2 - 1, 10));
        c.add(new Cal());
        f.pack();
        f.setVisible(true);
      }