快速业务通道

java日期时间选择控件(代码) - 编程入门网

作者 佚名技术 来源 NET编程 浏览 发布时间 2012-06-25
new Font("宋体", Font.PLAIN, 12));result.setLayout(new GridLayout(7,7));result.setBackground(Color.white);JLabel cell ;

for(int i=0;i<7;i++) {cell = new JLabel(colname[i]);cell.setHorizontalAlignment(JLabel.RIGHT);if (i==0 || i==6) cell.setForeground(weekendFontColor) ;else cell.setForeground(weekFontColor) ;result.add(cell) ;}

int actionCommandId = 0 ;for(int i = 0; i < 6; i++) for(int j = 0; j < 7; j++) {JButton numberButton = new JButton();numberButton.setBorder(null) ; numberButton.setHorizontalAlignment(SwingConstants.RIGHT);numberButton.setActionCommand(String.valueOf(actionCommandId)) ; numberButton.addActionListener(this) ;numberButton.setBackground(palletTableColor);numberButton.setForeground(dateFontColor) ;if (j==0 || j==6) numberButton.setForeground(weekendFontColor) ;else numberButton.setForeground(dateFontColor) ;daysButton[i][j] = numberButton;result.add(numberButton) ;actionCommandId ++ ;}

return result; }

private JDialog createDialog(Frame owner ) {JDialog result = new JDialog(owner,"日期时间选择",true) ;result.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);result.getContentPane().add(this,BorderLayout.CENTER) ;result.pack() ;result.setSize(width, height);return result ;}

void showDateChooser(Point position ) {Frame owner =(Frame)SwingUtilities.getWindowAncestor(DateChooserJButton.this) ;if (dialog==null || dialog.getOwner()!= owner) dialog = createDialog(owner ) ;dialog.setLocation(getAppropriateLocation(owner ,position ) ) ;flushWeekAndDay() ;dialog.show(); }

Point getAppropriateLocation(Frame owner ,Point position ) {Point result = new Point(position) ;Point p = owner.getLocation() ;int offsetX = (position.x+width) - (p.x + owner.getWidth() ) ;int offsetY = (position.y+height) - (p.y + owner.getHeight() ) ;

if (offsetX >0 ) {result.x -= offsetX ; }

if (offsetY >0 ) {result.y -= offsetY ; }

return result ;

}

private Calendar getCalendar() {Calendar result = Calendar.getInstance();result.setTime(getDate()) ;return result ;}

private int getSelectedYear() {return ((Integer)yearSpin.getValue()).intValue() ;}

private int getSelectedMonth() {return ((Integer)monthSpin.getValue()).intValue() ;}

private int getSelectedHour() {return ((Integer)hourSpin.getValue()).intValue() ;}

private void dayColorUpdate(boolean isOldDay) {Calendar c = getCalendar() ;int day = c.get(Calendar.DAY_OF_MONTH);c.set(Calendar.DAY_OF_MONTH,1);int actionCommandId =day-2+c.get(Calendar.DAY_OF_WEEK) ;int i = actionCommandId/7;int j = actionCommandId%7;if (isOldDay) daysButton[i][j].setForeground(dateFontColor) ;else daysButton[i][j].setForeground(todayBackColor) ;}

private void flushWeekAndDay() {Calendar c = getCalendar() ;c.set(Calendar.DAY_OF_MONTH,1);int maxDayNo = c.getActualMaximum(Calendar.DAY_OF_MONTH);int dayNo = 2 - c.get(Calendar.DAY_OF_WEEK) ;for(int i = 0; i < 6; i++) {for(int j = 0; j < 7; j++) {String s="" ;if (dayNo>=1 && dayNo<=maxDayNo ) s = String.valueOf(dayNo) ;daysButto

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号