Java万年历课程设计报告_第1页
Java万年历课程设计报告_第2页
Java万年历课程设计报告_第3页
Java万年历课程设计报告_第4页
Java万年历课程设计报告_第5页
已阅读5页,还剩25页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

Java 万 年 历 课 程 设 计 告ThismodelpaperwasrevisedbytheStandardizationOfficeonDecember10,2020Java: : 2013-6-29录3功能结构图… 3模块4需求4开发和运行环境… 4功能4详细思路… 4序思路… 5序运行主界面… 5流图… 6各模块功能实现及代码说明… 6MainFramel类… 6Lunar类… 14national类… 22SetClock类… 264小结… 345参考文献… 34Myeclipse。在上添加显示本时间会更加显示时间。无论对学还上班族自由职业者需经常看和找来规划自己将做得一些事情回忆在时间里已经做事情使之更加有利提升学习作进度。系统功能结构图主描述系统实现各个模块功能。世界时间

闹钟 询星期 农历查将北 纽 东 设 时 关 询 农京 约 京 置 间 闭 年历时 时 时 闹 到 月 与间 间 间 钟 , 日公闹 对 历铃 应 一响 的起星 实期现系统模块设计需求分析本程序求为1.使图形户界面能够实现与星询能够显示农历能够看世界时间能够添加闹钟Myeclipsewindows7:MainFrame、月拉式菜单来选择月Lunar农national世时间。月式显示与星SetClock来闹钟点击世时间按钮查询世时间点击闹钟按钮置闹钟显示系统当前时间显示作者信息。详细思路思路总天数算法if到输入之间每一是否为闰是闰该36否则36然后判断输入是否为定义若是令总天数S=否则用累加法算出定义到输入之间总天数再把输入一月到要输出月之间天数累加起来若该月是闰中月并且该月还大于二月再使总1否则不加既算出从定义一月一到输出该月一总天数。输出月第一天为星算法使总天数除72既为星若7则为星算出输出月第一天为星算法算出输出月第一天为星后把该前位置用空格补上并总该起一次输出天数直到月底该月中天数加上该月一日为星数字再除70即可完整输出该月如果1900则不予判断。主流MainFrame类importaa.Lunar;publicclassMainFrameextendsJFrameimplementsItemListener//{JPanelpanel=newJPanel(newBorderLayout());//JPanelpanel1=newJPanel();JPanelpanel2=newJPanel(newGridLayout(8,7));JPanelpanel3=newJPanel(newGridLayout(4,1));JLabel[]label=newJLabel[49];//JLabely_label=newJLabel("");JLabelm_label=newJLabel("");JLabeldashao=newJLabel(走",JLabel.CENTER);JLabelbing=newJLabel("",JLabel.CENTER);JLabelfeng=newJLabel("",JLabel.CENTER);JLabellabelTime=newJLabel("",JLabel.CENTER);JComboBoxcom1=newJComboBox();//JComboBoxcom2=newJComboBox();JButtonbut1=newJButton(""); //JButtonbut2=newJButton("");Calendarnow=Calendar.getInstance();publicMainFrame()//{super("万setSize(500,600);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);panel1.add(but1);panel1.add(y_label);panel1.add(com1);panel1.add(m_label);panel1.add(com2);panel1.add(but2);panel3.add(dashao);panel3.add(bing);panel3.add(feng);panel3.add(labelTime);for(inti=0;i<49;i++)//{label[i]=newJLabel("",JLabel.CENTER);panel2.add(label[i]);}panel.add(panel1,BorderLayout.NORTH);//panel.add(panel2,BorderLayout.CENTER);panel.add(panel3,BorderLayout.SOUTH);setContentPane(panel);setVisible(true);init();com1.addItemListener(this);//下拉组件监听com2.addItemListener(this);but1.addActionListener(newActionListener(){//按钮动作监听publicvoidactionPerformed(ActionEvente){newaa.SetClock(); //闹钟类}});but2.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){newaa.national();//世界时间类}});TimertimernewTimer(1000, newActionListener()//{publicvoidactionPerformed(ActionEventevt){Strings1newSimpleDateFormat("yyyy-MM-ddHH:mm:ss").format(newDate());labelTime.setText(""+s1);}});}

timer.start();//publicvoidinit()//{intyear,month,first_day_num;Stringlog[]={"","一","二","三","四","五","六"};for(inti=0;i<7;i++){label[i].setText(log[i]);}for(inti=0;i<49;i=i+7){label[i].setForeground(Color.red);//天为红色}for(inti=6;i<49;i=i+7){label[i].setForeground(Color.red);//六为红色}for(inti=1800;i<=2100;i++)//年份的拉1800-2100{com1.addItem(""+i);}for(inti=1;i<13;i++)//12月{com2.addItem(""+i);}first_day_num=(int)(now.get(Calendar.DAY_OF_WEEK));//获得日期month=(int)(now.get(Calendar.MONTH));//获得year=(int)(now.get(Calendar.YEAR));//获得年份com1.setSelectedIndex(year-1800);//将年设置为当前年份com2.setSelectedIndex(month);//将设置为当前月Resetday(first_day_num,year,month);//调用Resetday函数}publicintuse(intyear2,intmonth2)//use函数{intfirst_day;now.set(year2,month2,1);first_day=(int)(now.get(Calendar.DAY_OF_WEEK));returnfirst_day;}publicvoidstateChanged(){intyear3,month3,week3;year3=Integer.parseInt(com1.getSelectedItem().toString());month3=Integer.parseInt(com2.getSelectedItem().toString())-1;week3=use(year3,month3);Resetday(week3,year3,month3);//调用函数}public void Resetday(int week_log, int year_log, int month_log){//Resetday函数intmonth_day_score;//intcount;Lunarlunar;//lunarintmonth_day;String[LunarDate=newString[49];//month_day_score0;count=1;for(inti0i49i{//一起显示for(intj=0;j<49;j=j+7){if(i!=j&&i!=j+6)label[i].setForeground(Color.black);}for(intj=0;i<49;i=i+7){label[i].setForeground(Color.red);}for(intj=6;i<49;i=i+7){label[i].setForeground(Color.red);}}DatedatenewDate(year_logmonth_log11)//nowMONTH0始第几来说,DAY_OF_MONTH第一1.对于一年第几个来说,MONTH一0,二1...Calendarcal=Calendar.getInstance();cal.setTime(date);cal.add(Calendar.MONTH,-1);//前个月month_day_score=cal.getActualMaximum(Calendar.DAY_OF_MONTH);//最后一天month_day=month_day_score;for(inti=7;i<49;i++){//label[i].setText("");}week_log=week_log+6;//6month_day_score=month_day_score+week_log;lunar=newaa.Lunar();//Lunar类for(inti=0;i<month_day;i++){LunarDate[i]=lunar.getLunarDate(year_log, month_log+1,i+1);//}for(intiweek_logimonth_day_scorei++count++{//一些假期if(month_log==9&&count==1){label[i].setText(count+"国庆");label[i].setForeground(Color.red);}elseif(month_log==0&&count==1){label[i].setText(count+"元旦");label[i].setForeground(Color.red);}elseif(month_log==11&&count==24){label[i].setText(count+"平安夜");label[i].setForeground(Color.red);}elseif(month_log==11&&count==25){label[i].setText(count}elseif(month_log==1&&count==14){label[i].setText(count}elseif(month_log==4&&count==1){label[i].setText(count}elseif(LunarDate[i-week_log].equals(")||LunarDate[i-week_log].equals(")||LunarDate[i-week_log].equals(")||LunarDate[i-week_log].equals("中秋")){}else}}

label[i].setText("\n"+count+LunarDate[i-week_log]);label[i].setForeground(Color.red);label[i].setText(count+LunarDate[i-week_log]);publicvoiditemStateChanged(ItemEvente){stateChanged();//调用函数}publicstaticvoidmain(String[]args)//主函数{newMainFrame();}}Lunar类packageaa;publicclassLunar{privateintyear;privateintmonth;privateintday;privatebooleanleap;finalstaticStringchineseNumber[]={"一","二","三","四","五","六","七","八","九","十","十一","十二"};staticSimpleDateFormatchineseDateFormat=newSimpleDateFormat("yyyy年MM月dd日");finalstaticlong[]lunarInfo=newlong[]{0x04bd8, 0x04ae0, 0x0a570, 0x054d5, 0x0d260, 0x0d950, 0x16554, 0x056a0,0x09ad0,0x055d2,0x04ae0, 0x0a5b6, 0x0a4d0, 0x0d250, 0x1d255, 0x0b540, 0x0d6a0, 0x0ada2,0x095b0,0x14977,0x04970, 0x0a4b0, 0x0b4b5, 0x06a50, 0x06d40, 0x1ab54, 0x02b60, 0x09570,0x052f2,0x04970,0x06566, 0x0d4a0, 0x0ea50, 0x06e95, 0x05ad0, 0x02b60, 0x186e3, 0x092e0,0x1c8d7,0x0c950,0x0d4a0, 0x1d8a6, 0x0b550, 0x056a0, 0x1a5b4, 0x025d0, 0x092d0, 0x0d2b2,0x0a950,0x0b557,0x06ca0, 0x0b550, 0x15355, 0x04da0, 0x0a5d0, 0x14573, 0x052d0, 0x0a9a8,0x0e950,0x06aa0,0x0aea6, 0x0ab50, 0x04b60, 0x0aae4, 0x0a570, 0x05260, 0x0f263, 0x0d950,0x05b57,0x056a0,0x096d0, 0x04dd5, 0x04ad0, 0x0a4d0, 0x0d4d4, 0x0d250, 0x0d558, 0x0b540,0x0b5a0,0x195a6,0x095b0, 0x049b0, 0x0a974, 0x0a4b0, 0x0b27a, 0x06a50, 0x06d40, 0x0af46,0x0ab60,0x09570,0x04af5, 0x04970, 0x064b0, 0x074a3, 0x0ea50, 0x06b58, 0x055c0, 0x0ab60,0x096d5,0x092e0,0x0c960, 0x0d954, 0x0d4a0, 0x0da50, 0x07552, 0x056a0, 0x0abb7, 0x025d0,0x092d0,0x0cab5,0x0a950, 0x0b4a0, 0x0baa4, 0x0ad50, 0x055d9, 0x04ba0, 0x0a5b0, 0x15176,0x052b0,0x0a930,0x07954, 0x06aa0, 0x0ad50, 0x05b52, 0x04b60, 0x0a6e6, 0x0a4e0, 0x0d260,0x0ea65,0x0d530,0x05aa0, 0x076a3, 0x096d0, 0x04bd7, 0x04ad0, 0x0a4d0, 0x1d0b6, 0x0d250,0x0d520,0x0dd45,0x0b5a0, 0x056d0, 0x055b2, 0x049b0, 0x0a577, 0x0a4b0, 0x0aa50, 0x1b255,0x06d20,0x0ada0};//======传回农历y年的总天数finalprivatestaticintyearDays(inty){inti,sum=348;for(i=0x8000;i>0x8;i>>=1){if((lunarInfo[y-1900]&i)!=0)sum+=1;}return(sum+leapDays(y));}//======传回农历年闰月的天数finalprivatestaticintleapDays(inty){if(leapMonth(y)!=0){if((lunarInfo[y-1900]&0x10000)!=0)return30;elsereturn29;}elsereturn0;}//======1-12,0finalprivatestaticintleapMonth(intyreturn(int)(lunarInfo[y-1900]&0xf);}//=====mfinalprivatestaticintmonthDays(inty,intm){if((lunarInfo[y-1900]&(0x10000>>m))==0)return29;elsereturn30;}//======finalpublicStringanimalsYear(finalString[AnimalsnewString[]{"",""};returnAnimals[(year-4)%12];}//======offset0=finalprivatestaticStringcyclicalm(intnumfinalString[GannewString[]{"finalString[ZhinewString[]{"午","未","申","酉","戌","亥"};return(Gan[num%10]+Zhi[num%12]);}//======offset0=finalpublicStringcyclical(intnum=year-1900+36;return(cyclicalm(num));}publicstaticStringgetChinaDayString(intday){StringchineseTen[]={"","","",""};intn=day%10==0 9:day%10-1;if(day>30)return"";if(day==10)return"elsereturnchineseTen[day/10]+chineseNumber[n];}/***//**ymd.yearCyl3:1864相差数monCyl4:1900131以来,闰数dayCyl5:1900131相差40@paramcal@return*/publicStringgetLunarDate(intyear_log,intmonth_log,intday_log){//@SuppressWarnings("unused")intyearCyl,monCyl,dayCyl;intleapMonth=0;Stringnowadays;DatebaseDate=null;Datenowaday=null;try{baseDatechineseDateFormat.parse("1900131");}catch(ParseExceptione){e.printStackTrace(); //To change body of catch statement Options|FileTemplates.}nowadays=year_log+""+month_log+""+day_log+"";trynowaday=chineseDateFormat.parse(nowadays);}catch(ParseExceptione){e.printStackTrace(); //To change body of catch statement Options|FileTemplates.}//1900131dayCyloffset40;monCyl=14;//offset////i//offsetintiYeardaysOfYear0;for(iYear=1900;iYear<10000&&offset>0;iYear++){daysOfYear=yearDays(iYear);offset-=daysOfYear;monCyl+=12;}if(offset<0){offset+=daysOfYear;iYear--;monCyl-=12;}//year=iYear;yearCyl=iYear-1864;leapMonthleapMonth(iYear)//,1-12leapfalse;//offset,intiMonthdaysOfMonth0;for(iMonth=1;iMonth<13&&offset>0;iMonth++){//if(leapMonth>0&&iMonth==(leapMonth+1)&&!leap){--iMonth;leap=true;daysOfMonth=leapDays(year);}elsedaysOfMonth=monthDays(year,iMonth);offset-=daysOfMonth;//if(leap&&iMonth==(leapMonth+1))leap=false;if(!leap)monCyl++;}//offset0且刚才计算份要校正if(offset==0&&leapMonth>0&&iMonth==leapMonth+1){if(leap){leap=false;}else{leap=true;--iMonth;--monCyl;}}//offset0也要校正if(offset<0){offset+=daysOfMonth;--iMonth;--monCyl;}month=iMonth;day=offset+1;if(((month)==1)&&day==1){return}elseif(((month)==1)&&day==15){return}elseif(((month)==5)&&day==5)return";elseif(((month)==8)&&day==15)return";elseif(day==1)returnchineseNumber[month1";else}

returngetChinaDayString(day);publicStringtoString(){if(chineseNumber[month-1]=="一"&&getChinaDayString(day)=="初一")return"农历"+year+"年";elseif(getChinaDayString(day)=="初一")returnchineseNumber[month1";elsereturngetChinaDayString(day);//returnyear+"年"+(leap "闰":"")+chineseNumber[month-1]+"getChinaDayString(day);}}national类packageaa;publicclassnational{public national(){ComboBoxFrameframe=newComboBoxFrame();frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.setVisible(true);}}classComboBoxFrameextendsJFrame{publicstaticfinalintDEFAULT_WIDTH430;//publicstaticfinalintDEFAULT_HEIGHT200;publicComboBoxFrame(){setTitle("世界时间");//标题setSize(DEFAULT_WIDTH,DEFAULT_HEIGHT);//addpaneltoframeComboBoxPanelpanel=newComboBoxPanel();ContainercontentPane=getContentPane();contentPane.add(panel);Threadt=newThread(panel);//线程t.start();//线程启动}}classComboBoxPanelextendsJPanelimplementsRunnable{JLabellabel1=null;//定义各组件JLabellabel2=null;JLabellabel3=null;JLabellabel4=null;JLabellabel5=null;JComboBoxcombo1=null;JComboBoxcombo2=null;JComboBoxcombo3=null;//、纽约、东京privateStringtimeZone1="Etc/GMT-8";//privateStringtimeZone2="America/New_York";//纽约privateStringtimeZone3="Asia/Tokyo";//东publicComboBoxPanel(){label1=newJLabel();label2=newJLabel();label3=newJLabel();label4=newJLabel("下面的为纽约东的下拉选择其他地方");//添加标签label5newJLabel("同一个世界同一个梦想",JLabel.CENTER);label1.setFont(newFont("Dialog",Font.BOLD,12));//设置字体label2.setFont(newFont("Dialog",Font.BOLD,12));label3.setFont(newFont("Dialog",Font.BOLD,12));combo1=newJComboBox(TimeZone.getAvailableIDs());//下拉组件combo2=newJComboBox(TimeZone.getAvailableIDs());combo3=newJComboBox(TimeZone.getAvailableIDs());Clock();add(label4);add(label1);add(combo1);add(label2);add(combo2);add(label3);add(combo3);add(label5);JComboBoxActioncombo11Action=newJComboBoxAction(1);JComboBoxActioncombo12Action=newJComboBoxAction(2);JComboBoxActioncombo13Action=newJComboBoxAction(3);combo1.addActionListener(combo11Action);//下拉组件combo2.addActionListener(combo12Action);combo3.addActionListener(combo13Action);}privateclassJComboBoxActionimplementsActionListener{//实现下拉组件intType0;publicJComboBoxAction(inttype){Type=type;}publicvoidactionPerformed(ActionEventevent){if(Type==1){timeZone1=(String)combo1.getSelectedItem();}elseif(Type==2){timeZone2=(String)combo2.getSelectedItem();}elseif(Type==3){timeZone3=(String)combo3.getSelectedItem();}}}privatevoidClock(){SimpleDateFormatsd=newSimpleDateFormat("yyyy-MM-ddHH:mm:ss");//设置时间输出格式sd.setTimeZone(TimeZone.getTimeZone(timeZone1));//初始化标签StringstrDate=sd.format(newDate());label1.setText(strDate);sd.setTimeZone(TimeZone.getTimeZone(timeZone2));strDate=sd.format(newDate());label2.setText(strDate);sd.setTimeZone(TimeZone.getTimeZone(timeZone3));strDate=sd.format(newDate());label3.setText(strDate);}publicvoidrun({//while(trueClock();//函数try{Thread.sleep(1000);}catch(Exceptione){}}}}SetClock类packageaa;importjavax.swing.*;publicclassSetClockextendsJFrameimplementsRunnable{JLabelri,shi,fen,miao,dangqian,guanji;JButtonqueding,dakai;JTextFieldmusic,RI,SHI,FEN,MIAO;inth=0,f=0,m=0,r=0;booleanfo=false,foo=false;publicAudioClipsoumd1;intriqi,shizhong,fenzhong,miaozhong;publicSetClock(){Containerc=getContentPane();c.setLayout(newGridLayout(4,1));JPaneljp=newJPanel();dangqian=newJLabel();jp.add(dangqian);c.add(jp);JPaneljp3=newJPanel();guanjinewJLabel(":0000");jp3.add(guanji);c.add(jp3);JPaneljp1=newJPanel();music=newJTextField(20);dakainewJButton("");jp1.add(music);jp1.add(dakai);c.add(jp1);rinewJLabel("");RInewJTextField(4);shi=newJLabel("");SHI=newJTextField(4);fen=newJLabel("");FEN=newJTextField(4);miao=newJLabel("");MIAO=newJTextField(4);JPaneljp2=newJPanel();jp2.add(ri);jp2.add(RI);jp2.add(shi);jp2.add(SHI);jp2.add(fen);jp2.add(FEN);jp2.add(miao);jp2.add(MIAO);quedingnewJButton("");jp2.add(queding);c.add(jp2);setSize(400,160);setVisible(true);dakai.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEventevent){JFileChooserfileChoosernewJFileChooser()//fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);//,为和目录均可fileChooser.setCurrentDirectory(newFile("."))//当前目录publicbooleanaccept(Filefile//类型Stringnamefile.getName().toLowerCase();returnname.endsWith(".wav")||name.endsWith(".au")||file.isDirectory();}publicStringgetDescription(//描述return(*.wav,*.au)";}});if(fileChooser.showOpenDialog(SetClock.this)==JFileChooser.APPROVE_OPTION //,并判断是否点击了打开按钮StringfileName=fileChooser.getSelectedFile().getAbsolutePath();//得到或目录的绝对路径music.setText(fileName);}}});queding.addActionListener(newActionListener(voidactionPerformed(ActionEventevent(queding.getText().equals("try{r=Integer.parseInt(RI.getText());h=Integer.parseInt(SHI.getText());f=Integer.parseInt(FEN.getText());m=Integer.parseInt(MIAO.getText());if(1<=r&&r<=31&&0<=h&&h<=23&&0<=f&&f<=59&&0<=m&&m<=59){Datenow=newDate();SimpleDateFormatri=newSimpleDateFormat("dd");if(RI.getText()==null||RI.getText().equals("")){r=Integer.parseInt(ri.format(now));RI.setText(ri.format(now));}elser=Integer.parseInt(RI.getText());fo=true;}elseJOptionPane.showMessageDialog(null入时间错误");}catch(Exceptione){JOptionPane.showMessageDialog(null,入正的时间");}}else{try{fo=false;RI.setEditable(true);SHI.setEditable(true);FEN.setEditable(true);MIAO.setEditable(true);queding.setText("");soumd1.stop();}catch(ExceptionE){JOptionPane.showMessageDialog(null,关闭!");}}}});}publicvoidSet(){//SetClocks=newSetClock();Threadt1=newThread(this);t1.start();this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}publicvoidrun(){while(true){Datenow=newDate();dangqian.setText("now.toString());if(foo){

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论