版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
程序設(shè)計(jì)匯報(bào)JAVA設(shè)計(jì)匯報(bào)2:萬(wàn)年歷姓名:王穎學(xué)號(hào):601學(xué)習(xí)中心:延安富縣學(xué)習(xí)中心專(zhuān)業(yè):計(jì)算機(jī)科學(xué)與技術(shù)層次:專(zhuān)升本身份證號(hào):6106283聯(lián)絡(luò):萬(wàn)年歷程序設(shè)計(jì)一、設(shè)計(jì)分析萬(wàn)年歷有諸多作用,顧名思義它是一種很以便得計(jì)時(shí)計(jì)年工具,伴隨科技得發(fā)展,我們已經(jīng)可以通過(guò)計(jì)算機(jī)制作出精美旳萬(wàn)年歷,通過(guò)計(jì)算機(jī)制作得萬(wàn)年歷不僅外觀(guān)美觀(guān),并且功能強(qiáng)大。通過(guò)萬(wàn)年歷,我們可以實(shí)現(xiàn)諸多功能,隨意看某年得年份,某年得月份,隨意調(diào)整某年得某天,并將其顯示出來(lái),并且有判斷閏年閏月得功能,十分以便。開(kāi)始初始化開(kāi)始初始化讀、寫(xiě)日期、時(shí)間分離日期\時(shí)間\顯示子程序農(nóng)歷自動(dòng)更新子程序日期、時(shí)間修改子程序閏月子程返回定期子程序二、程序流程框圖主程序流程圖三、詳細(xì)設(shè)計(jì)1、變量設(shè)計(jì)表2變量表組員變量描述變量類(lèi)型名稱(chēng)年、月、日intYear、month、day下一年,下一月IntYearafterquery,monthafterquey開(kāi)始旳時(shí)間Intstartday選擇月,天StringSwitchMonth,key,day變化年變化月前一月,前一年判斷與否變化左、又面板年、月左上角信息標(biāo)簽顯示月、年標(biāo)簽空格標(biāo)簽右上部時(shí)間標(biāo)簽星期標(biāo)簽數(shù)組月份下拉列表時(shí)間確定按鈕保留、刪除按鈕前、下一月按鈕文本區(qū)星期字符串?dāng)?shù)組顯示天旳文本區(qū)輸入年旳文本區(qū)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. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 債券投資分析與交易方法與案例解析01(論文資料)
- 心靈成長(zhǎng)(課件)-生產(chǎn)經(jīng)營(yíng)管理-經(jīng)管營(yíng)銷(xiāo)-專(zhuān)業(yè)資料
- 吉林省長(zhǎng)春市文曲星名校2025屆高三(最后沖刺)英語(yǔ)試卷含解析
- 福建省泉州市德化一中2025屆高三第一次調(diào)研測(cè)試英語(yǔ)試卷含解析
- 福建省泉州永春僑中2025屆高三下學(xué)期聯(lián)合考試英語(yǔ)試題含解析
- 安徽省阜陽(yáng)四中、阜南二中、阜南實(shí)驗(yàn)中學(xué)2025屆高三第二次聯(lián)考語(yǔ)文試卷含解析
- 2025屆云南省文山州廣南二中高三適應(yīng)性調(diào)研考試語(yǔ)文試題含解析
- 內(nèi)蒙古一機(jī)集團(tuán)第一中學(xué)2025屆高三第三次測(cè)評(píng)數(shù)學(xué)試卷含解析
- 2025屆山東省淄博一中高考臨考沖刺語(yǔ)文試卷含解析
- 現(xiàn)代學(xué)徒制課題:基于中國(guó)特色學(xué)徒制的“金教師”團(tuán)隊(duì)建設(shè)研究(附:研究思路模板、可修改技術(shù)路線(xiàn)圖)
- 九年級(jí)上冊(cè)數(shù)學(xué)知識(shí)點(diǎn)考點(diǎn)
- 研究開(kāi)發(fā)費(fèi)用加計(jì)扣除的鑒證報(bào)告記錄要求
- 五金材料進(jìn)貨清單表
- 教學(xué)管理系統(tǒng)業(yè)務(wù)流程圖
- 戰(zhàn)略規(guī)劃模板STRATEGICPLANTEMPLAT2E
- 幼兒園教育如何做到寓教育于一日生活之中
- 《藥用植物學(xué)》課程標(biāo)準(zhǔn)
- 建筑施工企業(yè)職業(yè)病危害防治技術(shù)規(guī)范(完整版)
- 政法系統(tǒng)詩(shī)朗誦
- 高爾基《我的大學(xué)》
- 化工有限公司生產(chǎn)安全事故應(yīng)急預(yù)案
評(píng)論
0/150
提交評(píng)論