java日期时间选择控件(代码) - 编程入门网
class DateChooser extends JPanel implements ActionListener ,ChangeListener {int startYear = 1980; //默认【最小】显示年份int lastYear = 2050; //默认【最大】显示年份int width = 200; //界面宽度int height = 200; //界面高度
Color backGroundColor = Color.gray; //底色//月历表格配色----------------//Color palletTableColor = Color.white; //日历表底色Color todayBackColor = Color.orange; //今天背景色Color weekFontColor = Color.blue; //星期文字色Color dateFontColor = Color.black; //日期文字色Color weekendFontColor = Color.red; //周末文字色 //控制条配色------------------//Color controlLineColor = Color.pink; //控制条底色Color controlTextColor = Color.white; //控制条标签文字色 Color rbFontColor = Color.white; //RoundBox文字色Color rbBorderColor = Color.red; //RoundBox边框色Color rbButtonColor = Color.pink; //RoundBox按钮色Color rbBtFontColor = Color.red; //RoundBox按钮文字色 JDialog dialog ;JSpinner yearSpin ;JSpinner monthSpin ;JSpinner hourSpin ;JButton[][] daysButton = new JButton[6][7] ; DateChooser() { setLayout(new BorderLayout());setBorder(new LineBorder(backGroundColor, 2));setBackground(backGroundColor); JPanel topYearAndMonth = createYearAndMonthPanal();add(topYearAndMonth,BorderLayout.NORTH);JPanel centerWeekAndDay = createWeekAndDayPanal();add(centerWeekAndDay,BorderLayout.CENTER); } private JPanel createYearAndMonthPanal(){Calendar c = getCalendar() ;int currentYear =c.get(Calendar.YEAR);int currentMonth =c.get(Calendar.MONTH)+1;int currentHour =c.get(Calendar.HOUR_OF_DAY); JPanel result = new JPanel();result.setLayout(new FlowLayout());result.setBackground(controlLineColor); yearSpin = new JSpinner(new SpinnerNumberModel(currentYear,startYear,lastYear,1));yearSpin.setPreferredSize(new Dimension(48,20)) ;yearSpin.setName("Year") ;yearSpin.setEditor(new JSpinner.NumberEditor(yearSpin, "####")) ; yearSpin.addChangeListener(this) ; result.add(yearSpin) ; JLabel yearLabel = new JLabel("年");yearLabel.setForeground(controlTextColor);result.add(yearLabel); monthSpin = new JSpinner(new SpinnerNumberModel(currentMonth,1,12,1));monthSpin.setPreferredSize(new Dimension(35,20)) ;monthSpin.setName("Month") ;monthSpin.addChangeListener(this) ; result.add(monthSpin) ; JLabel monthLabel = new JLabel("月");monthLabel.setForeground(controlTextColor);result.add(monthLabel); hourSpin = new JSpinner(new SpinnerNumberModel(currentHour,0,23,1));hourSpin.setPreferredSize(new Dimension(35,20)) ;hourSpin.setName("Hour") ;hourSpin.addChangeListener(this) ; result.add(hourSpin) ; JLabel hourLabel = new JLabel("时");hourLabel.setForeground(controlTextColor);result.add(hourLabel); return result ;} java日期时间选择控件(代码)(3)时间:2007-05-30 private JPanel createWeekAndDayPanal() {String colname[] = {"日","一","二","三","四","五","六"};JPanel result = new JPanel();//设置固定字体,以免调用环境改变影响界面美观result.setFont( |
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢! |