| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 7285 人关注过本帖
标题:[原创]日期选择器
只看楼主 加入收藏
fqj793
Rank: 1
等 级:新手上路
威 望:2
帖 子:228
专家分:0
注 册:2006-12-9
收藏
得分:0 
学习的榜样!

知识改变命运!!!
2007-11-17 08:18
wenbin171
Rank: 1
等 级:新手上路
帖 子:119
专家分:0
注 册:2007-11-6
收藏
得分:0 

版主千里好厉害啊!


-------哼!谁说不可以-------
2007-11-17 10:22
Tony_bb
Rank: 1
等 级:新手上路
帖 子:37
专家分:0
注 册:2007-11-16
收藏
得分:0 

拿着研究一下~ 还有 内部类怎么会乱呢? 我比较喜欢内部类~

2007-11-17 10:25
魔鬼之子
Rank: 1
来 自:地狱之都
等 级:新手上路
帖 子:100
专家分:0
注 册:2007-9-22
收藏
得分:0 
真厉害!!!!!

只有仇恨才是永恒的
2008-01-05 15:47
longrm
Rank: 1
等 级:新手上路
帖 子:129
专家分:0
注 册:2007-6-18
收藏
得分:0 
原帖由 [bold][underline]千里冰封[/underline][/bold] 于 2007-8-29 13:16 发表 [url=http://bbs.][/url]
回到当前日期是有的,就是点击最下面的"今天:2007年08月29日"就回到当前的日期了至于加一个上一年和下一年,我当前也考虑了,加了两个按钮好像就很容易按错了 ...

不会啊,使用GridBagLayout布局,挺好的,给你改了一下,加了上一年和下一年,呵呵

java群: 55919698

My blog: http://hi.baidu.com/longrm
2008-01-07 10:33
longrm
Rank: 1
等 级:新手上路
帖 子:129
专家分:0
注 册:2007-6-18
收藏
得分:0 
有个问题,就是那个setToolTipText()在这里没用,运行时当鼠标移到上面的时候不显示提示信息,不知道怎么回事
程序代码:
    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)+"月");
        }
    }

java群: 55919698

My blog: http://hi.baidu.com/longrm
2008-01-07 10:36
longrm
Rank: 1
等 级:新手上路
帖 子:129
专家分:0
注 册:2007-6-18
收藏
得分:0 
还改了一个地方,  MyLabel.mouseReleased(),改为双击时选定日期,这样更人性化一点
      public void mouseReleased(MouseEvent e) {
            // 双击时选定
            if (e.getClickCount() == 2) {
                commit();
                return;
            }
            Point p=SwingUtilities.convertPoint(this,e.getPoint(),jp3);
            lm.setSelect(p,false);
        }

java群: 55919698

My blog: http://hi.baidu.com/longrm
2008-01-07 10:56
千里冰封
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:灌水之王
等 级:版主
威 望:155
帖 子:28477
专家分:59
注 册:2006-2-26
收藏
得分:0 
呵呵,你改得不错

可惜不是你,陪我到最后
2008-01-07 17:53
huangwei89
Rank: 1
等 级:新手上路
帖 子:127
专家分:0
注 册:2008-10-17
收藏
得分:0 
学习一下
2008-12-12 10:20
Limifan
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2009-12-17
收藏
得分:0 
你好,我打不开论坛里的文件,你可以把这个文件发送到我邮箱吗?我的邮箱地址fanliumei@谢谢了!
2009-12-18 08:54
快速回复:[原创]日期选择器
数据加载中...
 
   



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

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