版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
程序设计汇报JAVA设计汇报2:万年历姓名:王颖学号:601学习中心:延安富县学习中心专业:计算机科学与技术层次:专升本身份证号:6106283联络:万年历程序设计一、设计分析万年历有诸多作用,顾名思义它是一种很以便得计时计年工具,伴随科技得发展,我们已经可以通过计算机制作出精美旳万年历,通过计算机制作得万年历不仅外观美观,并且功能强大。通过万年历,我们可以实现诸多功能,随意看某年得年份,某年得月份,随意调整某年得某天,并将其显示出来,并且有判断闰年闰月得功能,十分以便。开始初始化开始初始化读、写日期、时间分离日期\时间\显示子程序农历自动更新子程序日期、时间修改子程序闰月子程返回定期子程序二、程序流程框图主程序流程图三、详细设计1、变量设计表2变量表组员变量描述变量类型名称年、月、日intYear、month、day下一年,下一月IntYearafterquery,monthafterquey开始旳时间Intstartday选择月,天StringSwitchMonth,key,day变化年变化月前一月,前一年判断与否变化左、又面板年、月左上角信息标签显示月、年标签空格标签右上部时间标签星期标签数组月份下拉列表时间确定按钮保留、删除按钮前、下一月按钮文本区星期字符串数组显示天旳文本区输入年旳文本区IntIntIntbooleanJPanelJLabelJLabelJLabelJLabelJLabelJLabel[]JComboBoxJButtonJButtonJButtonJTextAreaStringJTextFieldJTextFieldChangeyearmessagechangemonthmessagepriormonth,prioryearischange,ischange_priornextLeftPane,RightPaneYearLabel,MonthLabelAskShowDateBlankNorthMonthDayYearTopBarTitle[]MonthComboboxQuerySouthSave,SouthDeletePriorMonth,NextMonthCenterTextweek[]ShowDays[]YearText2、程序源代码importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;importjavax.swing.event.*;importjavax.swing.border.*;importjava.util.Calendar;importjava.util.*;importjava.io.*;importjava.io.IOException;publicclasscalendarextendsJFrameimplementsActionListener,MouseListener{intyear,month,day;intyearafterquery,monthafterquery;intstartday;StringSwitchMonth;Stringkey;intchangeyearmessage;intchangemonthmessage;intpriormonth;intprioryear;booleanischange=false;booleanischange_priornext=false;privateJPanelLeftPane,RightPane;//LeftsubprivateJLabelYearLabel;privateJLabelMonthLabel;privateJComboBoxMonthCombobox;privateJTextFieldShowDays[]=newJTextField[42];privateJTextFieldYearText;privateJLabelAsk;privateJLabelShowDate;privateJLabelBlank;privateJLabelTopBarTitle[]=newJLabel[7];privateJButtonToToday;privateJButtonQuery;privateStringweek[]={"SUN","MON","TUE","WED","THU","FRI","SAT"};//rightsubprivateJLabelNorthMonthDayYear;privateJTextAreaCenterText;privateJButtonSouthSave,SouthDelete;privateJButtonPriorMonth;privateJButtonNextMonth;publiccalendar(intyear,intmonth,intday){setTitle("MyCalendar&Textbook");//thelayoutaboutleftofjpaneLeftPane=newJPanel();JPanelLeftCenter=newJPanel();JPanelLeftNorth=newJPanel();//JPanelLeftSouth=newJPanel();LeftPane.setLayout(newBorderLayout());LeftPane.add(LeftNorth,BorderLayout.NORTH);LeftPane.add(LeftCenter,BorderLayout.CENTER);LeftPane.add(ToToday=newJButton("Gototoday",newImageIcon("../images/Handle.gif")),BorderLayout.SOUTH);ToToday.setBackground(Color.cyan);ToToday.addActionListener(this);LeftPane.validate();//thelayoutofLeftPane//LeftPane_NorthLeftNorth.setLayout(newGridLayout(3,1,0,-2));LeftNorth.add(Ask=newJLabel("Pleseinputtheinformationswhichyouwantquery:"));JPanelNorth=newJPanel(newFlowLayout(0,8,0));LeftNorth.add(North);North.add(YearLabel=newJLabel("Year:"));North.add(YearText=newJTextField(4));YearText.setBackground(Color.getHSBColor(30,20,50));YearText.setForeground(Color.blue);YearText.setFont(newFont("TimesRoman",Font.BOLD,17));YearText.addActionListener(this);YearText.setFocusable(true);North.add(Blank=newJLabel(""));North.add(MonthLabel=newJLabel("Month:"));North.add(MonthCombobox=newJComboBox());//addmonthtomonthcomboboxfor(inti=1;i<=12;i++){MonthCombobox.addItem(newInteger(i));}//SwitchthemonthMonthCombobox.setForeground(Color.blue);MonthCombobox.setFont(newFont("TimesRoman",Font.BOLD,12));North.add(Blank=newJLabel(""));North.add(Query=newJButton("Query"));Query.setForeground(Color.blue);Query.addActionListener(this);JPanelNorth2=newJPanel(newFlowLayout());LeftNorth.add(North2);North2.add(PriorMonth=newJButton(newImageIcon("../images/prior.gif")));PriorMonth.addActionListener(this);PriorMonth.setActionCommand("prior");priormonth=month;prioryear=year;SwitchMonth(month);North2.add(ShowDate=newJLabel(SwitchMonth+""+","+""+String.valueOf(year),SwingConstants.CENTER));ShowDate.setForeground(Color.blue);ShowDate.setFont(newFont("TimesRoman",Font.BOLD,14));North2.add(NextMonth=newJButton(newImageIcon("../images/next.gif")));NextMonth.addActionListener(this);NextMonth.setActionCommand("next");//LeftPane_CenterLeftCenter.setLayout(newGridLayout(7,7));//printtitlefor(inti=0;i<7;i++){TopBarTitle[i]=newJLabel();TopBarTitle[i].setText(week[i]);TopBarTitle[i].setForeground(Color.darkGray);TopBarTitle[i].setHorizontalAlignment(0);TopBarTitle[i].setBackground(Color.MAGENTA);TopBarTitle[i].setBorder(BorderFactory.createRaisedBevelBorder());LeftCenter.add(TopBarTitle[i]);}//printscreenandaddlistenerfor(inti=0;i<42;i++){ShowDays[i]=newJTextField();ShowDays[i].addMouseListener(this);ShowDays[i].setEditable(false);LeftCenter.add(ShowDays[i]);}//printthebodyofmonthPrintMonth(year,month,day);//thelayoutaboutrightofjpaneRightPane=newJPanel(newBorderLayout());JPanelRightCenter=newJPanel();JPanelRightNorth=newJPanel();JPanelRightSouth=newJPanel(newFlowLayout());RightPane.add(RightNorth,BorderLayout.NORTH);RightPane.add(RightCenter,BorderLayout.CENTER);RightPane.add(RightSouth,BorderLayout.SOUTH);RightNorth.add(NorthMonthDayYear=newJLabel(">>"+year+","+SwitchMonth+","+day+"<<"));key=year+"_"+SwitchMonth+"_"+day;NorthMonthDayYear.setForeground(Color.blue);NorthMonthDayYear.setFont(newFont("TimesRoman",Font.BOLD,17));RightCenter.add(CenterText=newJTextArea("pleasewritetoday'sthings."));CenterText.setLineWrap(true);CenterText.setSelectedTextColor(Color.blue);//CenterText.addActionListener(this);RightSouth.add(SouthSave=newJButton("Save"));SouthSave.setBackground(Color.cyan);SouthSave.addActionListener(this);SouthSave.setActionCommand("Save");RightSouth.add(SouthDelete=newJButton("Delete"));SouthDelete.setBackground(Color.cyan);SouthDelete.addActionListener(this);SouthDelete.setActionCommand("Delete");this.year=year;this.month=month;this.day=day;///addcontainertoputLeftPaneandRightPaneContainercon=getContentPane();JSplitPanesplit=newJSplitPane(JSplitPane.HORIZONTAL_SPLIT,RightPane,LeftPane);//gaibiancon.add(split,BorderLayout.CENTER);con.validate();//addCenterPanetonotepad//CenterPaneinitializesetFont(newFont("TimesNewRoman",Font.PLAIN,12));JScrollPanescrollpane=newJScrollPane(CenterText);scrollpane.setPreferredSize(newDimension(220,250));RightCenter.add(scrollpane);//initrandomaccessfile}//switchthemonthinenglishpublicvoidSwitchMonth(intmonth){switch(month){case1:SwitchMonth="Jan";break;case2:SwitchMonth="Feb";break;case3:SwitchMonth="Mar";break;case4:SwitchMonth="Apr";break;case5:SwitchMonth="May";break;case6:SwitchMonth="Jun";break;case7:SwitchMonth="Jul";break;case8:SwitchMonth="Aug";break;case9:SwitchMonth="Sep";break;case10:SwitchMonth="Qct";break;case11:SwitchMonth="Nov";break;case12:SwitchMonth="Dec";break;}}//printthebodyofthemonthpublicvoidPrintMonth(intyear,intmonth,intday){//Getstartdayoftheweekforthefirstdateinthemonthintstartday=GetStartDay(year,month);//Getnumberofdaysinthemonthintdayinmonth=GetNumOfDaysInMonth(year,month);//Printheader//PrintTitleAndScreen();//PrintbodyPrintMonthBody(startday,dayinmonth,day);}//PrintMonth(intyear,intmonth,intday)'sburdenpublicvoidPrintMonth(intyear,intmonth){//Getstartdayoftheweekforthefirstdateinthemonthintstartday=GetStartDay(year,month);//Getnumberofdaysinthemonthintdayinmonth=GetNumOfDaysInMonth(year,month);//Printheader//PrintbodyPrintMonthBody(startday,dayinmonth);}//PrintMonthBody(intstartday,intdayinmonth,intday)'sburdenpublicvoidPrintMonthBody(intstartday,intdayinmonth){for(inti=startday,n=1;i<startday+dayinmonth;i++){ShowDays[i].setText(""+n);ShowDays[i].setHorizontalAlignment(0);//letcenterif(n==day){ShowDays[i].setForeground(Color.green);ShowDays[i].setFont(newFont("TimesRoman",Font.BOLD,20));ShowDays[i].setBackground(Color.DARK_GRAY);}else{ShowDays[i].setFont(newFont("TimesRoman",Font.BOLD,12));ShowDays[i].setForeground(Color.white);ShowDays[i].setBackground(Color.DARK_GRAY);}n++;}for(inti=0;i<startday;i++){ShowDays[i].setText("");ShowDays[i].setBackground(Color.DARK_GRAY);}for(inti=startday+dayinmonth;i<42;i++){ShowDays[i].setText("");ShowDays[i].setBackground(Color.DARK_GRAY);}}//judgeleapyearisornotpublicbooleanIsLeapYear(intyear){if((year%400==0)||(year%4==0&&year%100!=0))returntrue;elsereturnfalse;}//judgethestartdayofamonthpublicintGetStartDay(intyear,intmonth){//gettotalnumberofdaysince1/1/0000intstartday0001=-32768;longtotalnumofdays=GetTotalNumOfDays(year,month);//returnthestartdayreturn(int)((totalnumofdays+startday0001)%7);}//judgethedaysofayearpubliclongGetTotalNumOfDays(intyear,intmonth){longtotal=0;//getthetotaldaysfrom-32767toyearfor(inti=-32767;i<year;i++){if(IsLeapYear(i))total=total+366;elsetotal=total+365;}//Adddaysfromjantothemonthpriortothecalendarmonthfor(inti=1;i<month;i++)total=total+GetNumOfDaysInMonth(year,i);returntotal;}//judgethedaysofamonthpublicintGetNumOfDaysInMonth(intyear,intmonth){if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)return31;if(month==4||month==6||month==9||month==11)return30;if(month==2){if(IsLeapYear(year))return29;elsereturn28;}return0;}publicvoidWriteRecord(){Stringcontent;content=CenterText.getText(); intn=content.length();char[]contentarr=newchar[n];try{inti=0;for(i=0;i<n;i++){contentarr[i]=content.charAt(i);}FileDiary=newFile("Diary");Diary.mkdir();Filemyfile=newFile("Diary\\"+key+".txt");FileWriterRecord=newFileWriter(myfile);for(i=0;i<contentarr.length;i++){Record.write(contentarr[i]);}Record.close();JOptionPane.showMessageDialog(this,"Savesuccess!");}catch(IOExceptionex){}}publicvoidReadRecord(){try{Stringcontent="";Filemyfile=newFile("Diary\\"+key+".txt");FileReaderRecord=newFileReader(myfile);if(myfile.exists()){longb=myfile.length();//char[]contentarr=newchar[b];intn=JOptionPane.showConfirmDialog(this,"Todayhaslogs,areyouread?","Confirm",JOptionPane.YES_NO_CANCEL_OPTION);if(n==JOptionPane.YES_OPTION){while((b=Record.read())!=-1){content=content+(char)b;}CenterText.setText(content);}} Record.close();}catch(IOExceptionex){CenterText.setText("Todayhasnotlogs.");}}publicvoidDeleteFile(){Stringfilepath="Diary\\"+key+".txt";Filemyfile=newFile(filepath);intn=JOptionPane.showConfirmDialog(this,"Areyousuredeletethefile?","Confirm",JOptionPane.YES_NO_CANCEL_OPTION);if(n==JOptionPane.YES_OPTION){if(myfile.exists()){Runtimert=Runtime.getRuntime();try{rt.exec("cmd/cdel"+filepath);}catch(IOExceptione){e.printStackTrace();}JOptionPane.showMessageDialog(this,"Deletesuccessed!");CenterText.setText("Todayhasnotlogs.");}else{JOptionPane.showMessageDialog(this,"Thefiledoesn'texist,deletefailured!");}}}publicvoidAboutActionListenerWay(){try{prioryear=Integer.parseInt(YearText.getText());priormonth=MonthCombobox.getSelectedIndex()+1;StringStrYearText=YearText.getText();changeyearmessage=Integer.parseInt(StrYearText);changemonthmessage=MonthCombobox.getSelectedIndex()+1;monthafterquery=changemonthmessage;yearafterquery=changeyearmessage;SwitchMonth(changemonthmessage);ShowDate.setText(SwitchMonth+""+","+""+String.valueOf(changeyearmessage));PrintMonth(changeyearmessage,changemonthmessage);ischange=true; }catch(Exceptionee){JOptionPane.showMessageDialog(this,"Theinputformatdoesn'tmatch","Error",JOptionPane.ERROR_MESSAGE);}}//doactonlistenerthingspublicvoidactionPerformed(ActionEventeAction){StringActionCommand=eAction.getActionCommand();//Handlebuttoneventsif(eAction.getSource()instanceofJButton){//Handlethequeryif("Query".equals(ActionCommand)){try{AboutActionListenerWay();}catch(Exceptionee){JOptionPane.showMessageDialog(this,"Theinputformatdoesn'tmatch","Error",JOptionPane.ERROR_MESSAGE);}}//Handlepriormonthif("prior".equals(ActionCommand)){if(priormonth>1){priormonth=priormonth-1;}else{priormonth=12;prioryear=prioryear-1;}PrintMonth(prioryear,priormonth,day);SwitchMonth(priormonth);ShowDate.setText(SwitchMonth+","+prioryear);NorthMonthDayYear.setText(">>"+SwitchMonth+","+day+","+prioryear+"<<");key=prioryear+"_"+SwitchMonth+"_"+day;ischange_priornext=true;}//Handlenextmonthif("next".equals(ActionCommand)){if(priormonth<12){priormonth=priormonth+1;}else{priormonth=1;prioryear=prioryear+1;}PrintMonth(prioryear,priormonth,day);SwitchMonth(priormonth);ShowDate.setText(SwitchMonth+","+prioryear);NorthMonthDayYear.setText(">>"+SwitchMonth+","+day+","+prioryear+"<<");key=prioryear+"_"+SwitchMonth+"_"+day;ischange_priornext=true;}//Handlethe"Gototoday"if("Gototoday".equals(ActionCommand)){PrintMonth(year,month,day);YearText.setText("");MonthCombobox.setSelectedIndex(0);SwitchMonth(month);ShowDate.setText(SwitchMonth+""+","+""+String.valueOf(year));NorthMonthDayYear.setText(">>"+year+SwitchMonth+","+day+","+"<<");key=year+"_"+SwitchMonth+"_"+day;priormonth=month;prioryear=year;ischange=false;}//Handlethe"Save"if("Save".equals(ActionCommand)){WriteRecord();}if("Delete".equals(ActionCommand)){DeleteFile();}}//HandleJTextFieldeventsif(eAction.getSource()instanceofJTextField){//HandlethequeryAboutActionListenerWay();}}publicvoidmousePressed(MouseEventeMouse){intday;try{//HandleShowDays[]eventsif(ischange==false){JTextFieldsource=(JTextField)eMouse.getSource();day=Integer.parseInt(source.getText());if(ischange_priornext==false){NorthMonthDayYear.setText(">>"+SwitchMonth+","+day+","+year+"<<");key=year+"_"+SwitchMonth+"_"+day;}else{NorthMonthDayYear.setText(">>"+SwitchMonth+","+day+","+prioryear+"<<");key=prioryear+"_"+SwitchMonth+"_"+day;}}elseJTextFieldsource=(JTextField)eMouse.getSource();day=Integer.parseInt(source.getText());if(ischange_priornext==false){SwitchMonth(changemonthmessage);NorthMonthDayYear.setText(">>"+SwitchMonth+","+day+","+changeyearmessage+"<<");key=changeyearmessage+"_"+SwitchMonth+"_"+day;}else{SwitchMonth(priormonth);NorthMonthDayYear.setText(">>"+SwitchMonth
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年四川货运从业资格考试模拟考试题目答案
- 2025加工承揽合同书
- 洛阳文化旅游职业学院《电气系统仿真》2023-2024学年第一学期期末试卷
- 2025汽车及运输合同书
- 建筑加固灰工施工合同
- 2024年书画艺术品交易合同3篇
- 环保公司水电节能措施
- 2024事业单位临时工聘任合同模板:后勤保障服务2篇
- 知识产权投资与融资
- 2025捐赠合同 标准版模板全
- 海警法智慧树知到答案章节测试2023年大连海洋大学
- 手机号码段归属地数据库(2016年3月)
- 《借贷记账法》教学设计
- 【试题】人教版二年级下数学暑假每日一练
- 卫生院关于开展满意度调查工作的实施方案
- 纺织材料学选择题
- YY/T 0916.1-2021医用液体和气体用小孔径连接件第1部分:通用要求
- 医务科工作思路(计划)6篇
- GB/T 13912-2020金属覆盖层钢铁制件热浸镀锌层技术要求及试验方法
- GA 614-2006警用防割手套
- 智慧购物中心整体解决方案
评论
0/150
提交评论