| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 638 人关注过本帖
标题:我的日历程序哪里错了????急!!!!
取消只看楼主 加入收藏
Javapet
Rank: 1
等 级:禁止访问
帖 子:80
专家分:0
注 册:2008-1-5
结帖率:50%
收藏
 问题点数:0 回复次数:0 
我的日历程序哪里错了????急!!!!
请问我的程序哪里出错了?为什么按了“<<”后会没有反应,并且当窗口缩小再还原时,日历的数值都清空了?
(因为我下面的程序是测试用的,所以只做了一个功能)
import java.util.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

class test extends JFrame
{
        private JPanel JP1=new JPanel();
        private JPanel JP2=new JPanel();
        private JPanel JP3=new JPanel();
        private int day,week,month,year;
        private JLabel left,center,right;
        Listener L;
        Calendar C;
        
        test()
        {
              C=Calendar.getInstance();
        month=C.get(Calendar.MONTH);
        year=C.get(Calendar.YEAR);
        
              this.setLayout(null);
              JP1.setLayout(new GridLayout(1,7));
                JP1.add(new JLabel("日 "));
                JP1.add(new JLabel("一 "));
                JP1.add(new JLabel("二 "));
                JP1.add(new JLabel("三 "));
                JP1.add(new JLabel("四 "));
                JP1.add(new JLabel("五 "));
                JP1.add(new JLabel("六"));
                this.add(JP1);
        JP1.setBounds(5,0,200,25);
        
        JP2.setLayout(new GridLayout(6,7));
        JP2.setBackground(Color.white);
        GregorianCalendar G1=new GregorianCalendar(year,month,1);   
        week=G1.get(Calendar.DAY_OF_WEEK);
                for(int i=1;i<=week-1;i++)
        {
                JP2.add(new JLabel(""));
        }
        for(int i=1;i<=31;i++)
        {
                JP2.add(new JLabel(String.valueOf(i),JLabel.CENTER));
        }
        this.add(JP2);
        JP2.setBounds(0,25,195,100);
        
        JP3.setLayout(new BorderLayout());
        GregorianCalendar G2=new GregorianCalendar();
        day=G2.get(Calendar.DAY_OF_MONTH);
        left=new JLabel("<<");
        right=new JLabel(">>");
        center=new JLabel("今天:"+String.valueOf(year)+"年"+String.valueOf(month+1)+"月"+String.valueOf(day)+"日",JLabel.CENTER);
        JP3.add(left,BorderLayout.WEST);
        JP3.add(center,BorderLayout.CENTER);
        JP3.add(right,BorderLayout.EAST);
        this.add(JP3);
        JP3.setBounds(5,125,185,50);
        
        left.addMouseListener(new Listener());
    }
      void update()
    {
            JP2.removeAll();
            JP3.removeAll();
              GregorianCalendar G3=new GregorianCalendar(year,month,1);   
              week=G3.get(Calendar.DAY_OF_WEEK);
                for(int i=1;i<=week-1;i++)
              {
                      JP2.add(new JLabel(""));
              }
               for(int i=1;i<=29;i++)
              {
                      JP2.add(new JLabel(String.valueOf(i),JLabel.CENTER));
              }        
              center=new JLabel("今天:"+String.valueOf(year)+"年"+String.valueOf(month)+"月"+String.valueOf(day)+"日");
          JP3.add(left,BorderLayout.WEST);
          JP3.add(center,BorderLayout.CENTER);
          JP3.add(right,BorderLayout.EAST);
          add(JP3);
          JP3.setBounds(5,125,185,50);
      }
        class Listener extends MouseAdapter
    {      
                public void mousePressed(MouseEvent e)
                {
                        month=month-1;
                  update();
                }
    }
    public static void main(String[] args)
        {
              test JF=new test();
                JF.setSize(200,200);
                JF.setLocation(250,100);
                JF.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                JF.setResizable(false);
                JF.setVisible(true);
        }
}
搜索更多相关主题的帖子: 日历 
2008-03-23 00:48
快速回复:我的日历程序哪里错了????急!!!!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.036391 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved