ImageVerifierCode 换一换
格式:DOCX , 页数:11 ,大小:33.68KB ,
资源ID:21278016      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/21278016.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(Java 日期选择器Word文档格式.docx)为本站会员(b****5)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

Java 日期选择器Word文档格式.docx

1、import java.text.SimpleDateFormat;import java.util.ArrayList;import java.util.Calendar;import java.util.Comparator;import java.util.Date;import java.util.List;import javax.swing.BorderFactory;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;imp

2、ort javax.swing.Popup;import javax.swing.PopupFactory;import javax.swing.SwingUtilities;import javax.swing.event.AncestorEvent;import javax.swing.event.AncestorListener;public class DateChooser extends JPanelprivate Date initDate;private Calendar now=Calendar.getInstance();private Calendar select;pr

3、ivate JPanel monthPanel;/月历private JP1 jp1;/四块面板,组成private JP2 jp2;private JP3 jp3;private JP4 jp4;private Font font=new Font(宋体,Font.PLAIN,12);private final LabelManager lm=new LabelManager();private JLabel showDate;/,toSelect;private SimpleDateFormat sdf=new SimpleDateFormat(yyyy年MM月dd日);private b

4、oolean isShow=false;private Popup pop;public DateChooser() this(new Date();public DateChooser(Date date)initDate=date;select=Calendar.getInstance();select.setTime(initDate);initPanel();initLabel();public void setEnabled(boolean b)super.setEnabled(b);showDate.setEnabled(b);public Date getDate()return

5、 select.getTime();/根据初始化的日期,初始化面板private void initPanel()monthPanel=new JPanel(new BorderLayout();monthPanel.setBorder(BorderFactory.createLineBorder(Color.BLUE);JPanel up=new JPanel(new BorderLayout();up.add(jp1=new JP1(),BorderLayout.NORTH);up.add(jp2=new JP2(),BorderLayout.CENTER);monthPanel.add(

6、jp3=new JP3(),BorderLayout.CENTER);monthPanel.add(up,BorderLayout.NORTH);monthPanel.add(jp4=new JP4(),BorderLayout.SOUTH);this.addAncestorListener(new AncestorListener()public void ancestorAdded(AncestorEvent event) public void ancestorRemoved(AncestorEvent event) /只要祖先组件一移动,马上就让popup消失public void a

7、ncestorMoved(AncestorEvent event) hidePanel(););/初始化标签private void initLabel()showDate=new JLabel(sdf.format(initDate);showDate.setRequestFocusEnabled(true);showDate.addMouseListener(new MouseAdapter()public void mousePressed(MouseEvent me)showDate.requestFocusInWindow();/toSelect=new JLabel(sdf.for

8、mat(initDate);toSelect.setBorder(BorderFactory.createLineBorder(Color.BLACK);toSelect.setRequestFocusEnabled(true);this.setBackground(Color.WHITE);this.add(showDate,BorderLayout.CENTER);this.add(toSelect,BorderLayout.EAST);this.setPreferredSize(new Dimension(90,25);this.setBorder(BorderFactory.creat

9、eLineBorder(Color.GRAY);public void mouseEntered(MouseEvent me)if(showDate.isEnabled()showDate.setCursor(new Cursor(Cursor.HAND_CURSOR);showDate.setForeground(Color.RED);public void mouseExited(MouseEvent me)showDate.setCursor(new Cursor(Cursor.DEFAULT_CURSOR);showDate.setForeground(Color.BLACK);sho

10、wDate.setForeground(Color.CYAN);if(isShow)elseshowPanel(showDate);public void mouseReleased(MouseEvent me)showDate.addFocusListener(new FocusListener()public void focusLost(FocusEvent e)public void focusGained(FocusEvent e)/根据新的日期刷新private void refresh()jp1.updateDate();jp3.updateDate();SwingUtiliti

11、es.updateComponentTreeUI(this);/提交日期private void commit()System.out.println(选中的日期是:+sdf.format(select.getTime();showDate.setText(sdf.format(select.getTime();private void hidePanel()if(pop!=null)isShow=false;pop.hide();pop=null;private void showPanel(Component owner)Point show=new Point(0,showDate.ge

12、tHeight();SwingUtilities.convertPointToScreen(show,showDate);Dimension size=Toolkit.getDefaultToolkit().getScreenSize();int x=show.x;int y=show.y;if(xsize.width-295)x=size.width-295;if(yy-=188;pop=PopupFactory.getSharedInstance().getPopup(owner,monthPanel,x,y);pop.show();isShow=true;private class JP

13、1 extends JPanelJLabel left,right,center;public JP1()super(new BorderLayout();this.setBackground(new Color(160,185,215);initJP1();private void initJP1()left=new JLabel( right.setToolTipText(下一月left.setBorder(BorderFactory.createEmptyBorder(10,0,0,0);right.setBorder(BorderFactory.createEmptyBorder(10

14、,0,0,0);center=new JLabel(updateDate();this.add(left,BorderLayout.WEST);this.add(center,BorderLayout.CENTER);this.add(right,BorderLayout.EAST);this.setPreferredSize(new Dimension(295,25);left.addMouseListener(new MouseAdapter()left.setCursor(new Cursor(Cursor.HAND_CURSOR);left.setForeground(Color.RE

15、D);left.setCursor(new Cursor(Cursor.DEFAULT_CURSOR);left.setForeground(Color.BLACK);select.add(Calendar.MONTH,-1);left.setForeground(Color.WHITE);refresh();right.addMouseListener(new MouseAdapter()right.setCursor(new Cursor(Cursor.HAND_CURSOR);right.setForeground(Color.RED);right.setCursor(new Curso

16、r(Cursor.DEFAULT_CURSOR);right.setForeground(Color.BLACK);select.add(Calendar.MONTH,1);right.setForeground(Color.WHITE);private void updateDate()center.setText(select.get(Calendar.YEAR)+年+(select.get(Calendar.MONTH)+1)+月private class JP2 extends JPanelpublic JP2()this.setPreferredSize(new Dimension(

17、295,20);protected void paintComponent(Graphics g)g.setFont(font);g.drawString(星期日 星期一 星期二 星期三 星期四 星期五 星期六,5,10);g.drawLine(0,15,getWidth(),15);private class JP3 extends JPanelpublic JP3()super(new GridLayout(6,7);this.setPreferredSize(new Dimension(295,100);initJP3();private void initJP3()public void updateDate()this.removeAll();lm.clear();Date temp=select.getTime();Calendar select=Calendar.getInstance();select.setTime(temp);select.set(Calendar.DAY_OF_MONTH,1);int index=select.get(Calenda

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1