資源描述:
《swing日期控件》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫。
1、Swing日期控件一、截圖:二、源代碼:packagecom.longtu.rpt.app.view.rptview.multisheet;importjava.util.Calendar;importjavax.swing.JComboBox;importjavax.swing.JTable;importjavax.swing.table.DefaultTableModel;publicclassDateChoiceActive{//初始化年選擇下拉框publicstaticString[]i
2、nitItemsYear(){String[]arrYear=newString[70];for(inti=1980;i<2050;i++){arrYear[i-1980]=String.valueOf(i);}returnarrYear;}//初始化月選擇下拉框publicstaticvoidinitItemsMonth(JComboBoxcmbMonth){cmbMonth.addItem("一月");cmbMonth.addItem("二月");cmbMonth.addItem("三月")
3、;cmbMonth.addItem("四月");cmbMonth.addItem("五月");cmbMonth.addItem("六月");cmbMonth.addItem("七月");cmbMonth.addItem("八月");cmbMonth.addItem("九月");cmbMonth.addItem("十月");cmbMonth.addItem("十一月");cmbMonth.addItem("十二月");}publicstaticStringinitComboboxSelected(
4、intmonth){if(1==month){return"一月";}elseif(2==month){return"二月";}elseif(3==month){return"三月";}elseif(4==month){return"四月";}elseif(5==month){return"五月";}elseif(6==month){return"六月";}elseif(7==month){return"七月";}elseif(8==month){return"八月";}elseif(9==mo
5、nth){return"九月";}elseif(10==month){return"十月";}elseif(11==month){return"十一月";}else{return"十二月";}}publicstaticintgetSelectItemValue(Stringmonth){if("一月".equals(month)){return1;}elseif("二月".equals(month)){return2;}elseif("三月".equals(month)){return3;}el
6、seif("四月".equals(month)){return4;}elseif("五月".equals(month)){return5;}elseif("六月".equals(month)){return6;}elseif("七月".equals(month)){return7;}elseif("八月".equals(month)){return8;}elseif("九月".equals(month)){return9;}elseif("十月".equals(month)){return10;
7、}elseif("十一月".equals(month)){return11;}elseif("十二月".equals(month)){return12;}return0;}privatestaticintgetCurrentMonthFirstDay(intyear,intmonth){Calendarnow=Calendar.getInstance();now.set(year,month-1,1);intweek=now.get(Calendar.DAY_OF_WEEK)-1;returnw
8、eek;}privatestaticintgetCurrentMonthDays(intyear,intmonth){intdays=0;//存儲(chǔ)當(dāng)月的天數(shù)booleanisRn=false;//是否閏年for(inti=1900;i9、
10、i%400==0){isRn=true;}else{}}for(inti=1;i<=month;i++){switch(i){case1:case3:case5:case7:case8:case1