java程序設計報告萬年歷_第1頁
java程序設計報告萬年歷_第2頁
java程序設計報告萬年歷_第3頁
java程序設計報告萬年歷_第4頁
java程序設計報告萬年歷_第5頁
已閱讀5頁,還剩14頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領

文檔簡介

1、程序設計報告JAVA設計報告2:萬年歷姓名:王穎學號:001學習中心:XX富縣學習中心專業(yè):計算機科學與技術層次:專升本XX號:3聯(lián)系:萬年歷程序設計一、設計分析萬年歷有很多作用,顧名思義它是一種很方便得計時計年工具,隨著科技得開展,我們已經(jīng)可以通過計算機制作出精巧的萬年歷,通過計算機制作得萬年歷不但外觀美觀,而且功能強大。通過萬年歷,我們可以實現(xiàn)很多功能,隨意看某年得年份,某年得月份,隨意調(diào)整某年得某天,并將其顯示出來,而且有判斷閏年閏月得功能,十分方便。二、程序流程框圖主程序流程圖計算PE岳天做給秉,總無射中的數(shù)據(jù)為當箭日期在陽歷中的第幾天三、具體設計1、變量設計表2變量表成員變量描述變量

2、類型名稱年、月、日intYeahmonth、day下一年,下一IntYearafterquery,monthafterquey月開場的時間Intstartday選擇月,天StringSwitchMonth,key,day改變年改變月IntChangeyearmessage刖一月,刖一Intchangemonthmessage年Intpriormonth,prioryear判斷是否改變booleanischangeischange_priornext左、又面板JPanelLeftPane,RightPane年、月JLabelYearLabelMonthLabel左上角信息標JLabelAsk簽J

3、LabelShowDate顯示月、年標JLabelBlank簽JLabelNorthMonthDayYear空格標簽JLabel口TopBarTitle口右上部時間標oBoxMonthbobox簽uttonQuery星期標簽數(shù)組uttonSouthSave,SouthDelete月份下拉列表uttonPriorMonth,NextMonth時間確定按鈕JTextAreaCenterText保存、刪除按Stringweek鈕JTextFieldShowDays口前、下一月按JTextFieldYearText鈕文本區(qū)星期字符串數(shù)組顯小大的文本區(qū)輸入年的義本區(qū)2、程序源代碼importjava.a

4、wt.*;importjava.awt.event.*;importjavax.swing.*;importjavax.swing.event.*;importjavax.swing.border.*;importjava.util.Calendar;importjava.util.*;importjava.io.*;importjava.io.IOException;publicclasscalendarextendsJFrameimplementsActionListener,MouseListenerintyear,month,day;intyearafterquery,monthaft

5、erquery;intstartday;StringSwitchMonth;Stringkey;intchangeyearmessage;intchangemonthmessage;intpriormonth;intprioryear;booleanischange=false;booleanischange_priornext=false;privateJPanelLeftPane,RightPane;/LeftsubprivateJLabelYearLabel;privateJLabelMonthLabel;privateoBoxMonthbobox;privateJTextFieldSh

6、owDays=newJTextField42;privateJTextFieldYearText;privateJLabelAsk;privateJLabelShowDate;privateJLabelBlank;privateJLabelTopBarTitle=newJLabel7;privateuttonToToday;privateuttonQuery;privateStringweek="SUN","MON","TUE","WED","THU","FRI","

7、;SAT"/rightsubprivateJLabelNorthMonthDayYear;privateJTextAreaCenterText;privateuttonSouthSave,SouthDelete;privateuttonPriorMonth;privateuttonNextMonth;publiccalendar(intyear,intmonth,intday)setTitle("MyCalendar&Textbook");/thelayoutaboutleftofjpaneLeftPane=newJPanel();JPanelLeftCe

8、nter=newJPanel();JPanelLeftNorth=newJPanel();/JPanelLeftSouth=newJPanel();LeftPane.setLayout(newBorderLayout();LeftPane.add(LeftNorth,BorderLayout.NORTH);LeftPane.add(LeftCenter,BorderLayout.CENTER);LeftPane.add(ToToday=newutton("Gototoday",newImageIcon("./images/Handle.gif"),Bor

9、derLayout.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(newFlowLayo

10、ut(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);Yea

11、rText.setFocusable(true);North.add(Blank=newJLabel("");North.add(MonthLabel=newJLabel("Month:");North.add(Monthbobox=newoBox();/addmonthtomonthboboxfor(inti=1;i<=12;i+)Monthbobox.addItem(newInteger(i);/SwitchthemonthMonthbobox.setForeground(Color.blue);Monthbobox.setFont(newFo

12、nt("TimesRoman",Font.BOLD,12);North.add(Blank=newJLabel("");North.add(Query=newutton("Query");Query.setForeground(Color.blue);Query.addActionListener(this);JPanelNorth2=newJPanel(newFlowLayout();LeftNorth.add(North2);North2.add(PriorMonth=newutton(newImageIcon("./i

13、mages/prior.gif");PriorMonth.addActionListener(this);PriorMonth.setActionmand("prior");priormonth=month;prioryear=year;SwitchMonth(month);North2.add(ShowDate=newJLabel(SwitchMonth+""+","+"+String.valueOf(year),SwingConstants.CENTER);ShowDate.setForeground(Colo

14、r.blue);ShowDate.setFont(newFont("TimesRoman",Font.BOLD,14);North2.add(NextMonth=newutton(newImageIcon("./images/next.gif");NextMonth.addActionListener(this);NextMonth.setActionmand("next");/LeftPane_CenterLeftCenter.setLayout(newGridLayout(7,7);/printtitlefor(inti=0;i&

15、lt;7;i+)TopBarTitlei=newJLabel();TopBarTitlei.setText(weeki);TopBarTitlei.setForeground(Color.darkGray);TopBarTitlei.setHorizontalAlignment(0);TopBarTitlei.setBackground(Color.MAGENTA);TopBarTitlei.setBorder(BorderFactory.createRaisedBevelBorder();LeftCenter.add(TopBarTitlei);/printscreenandaddliste

16、nerfor(inti=0;i<42;i+)ShowDaysi=newJTextField();ShowDaysi.addMouseListener(this);ShowDaysi.setEditable(false);LeftCenter.add(ShowDaysi);/printthebodyofmonthPrintMonth(year,month,day);/thelayoutaboutrightofjpaneRightPane=newJPanel(newBorderLayout();JPanelRightCenter=newJPanel();JPanelRightNorth=ne

17、wJPanel();JPanelRightSouth=newJPanel(newFlowLayout();RightPane.add(RightNorth,BorderLayout.NORTH);RightPane.add(RightCenter,BorderLayout.CENTER);RightPane.add(RightSouth,BorderLayout.SOUTH);RightNorth.add(NorthMonthDayYear=newJLabel(">>"+year+","+SwitchMonth+","+d

18、ay+"<<");key=year+"_"+SwitchMonth+"_"+day;NorthMonthDayYear.setForeground(Color.blue);NorthMonthDayYear.setFont(newFont("TimesRoman",Font.BOLD,17);RightCenter.add(CenterText=newJTextArea("pleasewritetoday'sthings.");CenterText.setLineWrap(t

19、rue);CenterText.setSelectedTextColor(Color.blue);/CenterText.addActionListener(this);RightSouth.add(SouthSave=newutton("Save");SouthSave.setBackground(Color.cyan);SouthSave.addActionListener(this);SouthSave.setActionmand("Save");RightSouth.add(SouthDelete=newutton("Delete&qu

20、ot;);SouthDelete.setBackground(Color.cyan);SouthDelete.addActionListener(this);SouthDelete.setActionmand("Delete");this.year=year;this.month=month;this.day=day;/addcontainertoputLeftPaneandRightPaneContainercon=getContentPane();JSplitPanesplit=newJSplitPane(JSplitPane.HORIZONTAL_SPLIT,Righ

21、tPane,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

22、);/initrandomaccessfile/switchthemonthinenglishpublicvoidSwitchMonth(intmonth)switch(month)case 1:SwitchMonth="Jan"break;case 2:SwitchMonth="Feb"break;case 3:SwitchMonth="Mar"break;case 4:SwitchMonth="Apr"break;case 5:SwitchMonth="May"break;case 6:Sw

23、itchMonth="Jun"break;case 7:SwitchMonth="Jul"break;case 8:SwitchMonth="Aug"break;case 9:SwitchMonth="Sep"break;case 10:SwitchMonth="Qct"break;case 11:SwitchMonth="Nov"break;case 12:SwitchMonth="Dec"break;/printthebodyofthemonthpub

24、licvoidPrintMonth(intyear,intmonth,intday)/Getstartdayoftheweekforthefirstdateinthemonthintstartday=GetStartDay(year,month);/Getnumberofdaysinthemonthintdayinmonth=GetNumOfDaysInMonth(year,month);/Printheader/PrintTitleAndScreen();/PrintbodyPrintMonthBody(startday,dayinmonth,day);/PrintMonth(intyear

25、,intmonth,intday)'sburdenpublicvoidPrintMonth(intyear,intmonth)/Getstartdayoftheweekforthefirstdateinthemonthintstartday=GetStartDay(year,month);/Getnumberofdaysinthemonthintdayinmonth=GetNumOfDaysInMonth(year,month);/Printheader/PrintbodyPrintMonthBody(startday,dayinmonth);/PrintMonthBody(intst

26、artday,intdayinmonth,intday)'sburdenpublicvoidPrintMonthBody(intstartday,intdayinmonth)for(inti=startday,n=1;i<startday+dayinmonth;i+)ShowDaysi.setText(""+n);ShowDaysi.setHorizontalAlignment(0);/letcenterif(n=day)ShowDaysi.setForeground(Color.green);ShowDaysi.setFont(newFont("T

27、imesRoman",Font.BOLD,20);ShowDaysi.setBackground(Color.DARK_GRAY);elseShowDaysi.setFont(newFont("TimesRoman",Font.BOLD,12);ShowDaysi.setForeground(Color.white);ShowDaysi.setBackground(Color.DARK_GRAY);n+;for(inti=0;i<startday;i+)ShowDaysi.setText("");ShowDaysi.setBackgrou

28、nd(Color.DARK_GRAY);for(inti=startday+dayinmonth;i<42;i+)ShowDaysi.setText("");ShowDaysi.setBackground(Color.DARK_GRAY);/judgeleapyearisornotpublicbooleanIsLeapYear(intyear)if(year%400=0)|(year%4=0&&year%100!=0)returntrue;elsereturnfalse;/judgethestartdayofamonthpublicintGetStar

29、tDay(intyear,intmonth)/gettotalnumberofdaysince1/1/0000intstartday0001=-32768;longtotalnumofdays=GetTotalNumOfDays(year,month);/returnthestartdayreturn(int)(totalnumofdays+startday0001)%7);/judgethedaysofayearpubliclongGetTotalNumOfDays(intyear,intmonth)longtotal=0;/getthetotaldaysfrom-32767toyearfo

30、r(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|mo

31、nth=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();charcontentarr=newcharn;tryinti=0;for(i=0;i<n;i+)contentarri=co

32、ntent.charAt(i);FileDiary=newFile("Diary");Diary.mkdir();Filemyfile=newFile("Diary"+key+".txt");FileWriterRecord=newFileWriter(myfile);for(i=0;i<contentarr.length;i+)Record.write(contentarri);Record.close();JOptionPane.showMessageDialog(this,"Savesuccess!")

33、;catch(IOExceptionex)publicvoidReadRecord()tryStringcontent=""Filemyfile=newFile("Diary"+key+".txt");FileReaderRecord=newFileReader(myfile);if(myfile.exists()longb=myfile.length();/charcontentarr=newcharb;youintn=JOptionPane.showConfirmDialog(this,"Todayhaslogs,are

34、read?","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="D

35、iary"+key+".txt"Filemyfile=newFile(filepath);theintn=JOptionPane.showConfirmDialog(this,"Areyousuredeletefile?","Confirm",JOptionPane.YES_NO_CANCEL_OPTION);if(n=JOptionPane.YES_OPTION)if(myfile.exists()Runtimert=Runtime.getRuntime();tryrt.exec("cmd/cdel"+

36、filepath);catch(IOExceptione)e.printStackTrace();JOptionPane.showMessageDialog(this,"Deletesuccessed!");CenterText.setText("Todayhasnotlogs.");elseJOptionPane.showMessageDialog(this,"Thefiledoesn'texist,deletefailured!");publicvoidAboutActionListenerWay()tryprioryea

37、r=Integer.parseInt(YearText.getText();priormonth=Monthbobox.getSelectedIndex()+1;StringStrYearText=YearText.getText();changeyearmessage=Integer.parseInt(StrYearText);changemonthmessage=Monthbobox.getSelectedIndex()+1;monthafterquery=changemonthmessage;yearafterquery=changeyearmessage;SwitchMonth(cha

38、ngemonthmessage);ShowDate.setText(SwitchMonth+""+","+""+String.valueOf(changeyearmessage);PrintMonth(changeyearmessage,changemonthmessage);ischange=true;catch(Exceptionee)doesn'tJOptionPane.showMessageDialog(this,"Theinputformatmatch","Error",JOp

39、tionPane.ERROR_MESSAGE);/doactonlistenerthingspublicvoidactionPerformed(ActionEventeAction)StringActionmand=eAction.getActionmand();/Handlebuttoneventsif(eAction.getSource()instanceofutton)/Handlethequeryif("Query".equals(Actionmand)tryAboutActionListenerWay();catch(Exceptionee)doesn't

40、JOptionPane.showMessageDialog(this,"Theinputformatmatch","Error",JOptionPane.ERROR_MESSAGE);/Handlepriormonthif("prior".equals(Actionmand)if(priormonth>1)priormonth=priormonth-1;elsepriormonth=12;prioryear=prioryear-1;PrintMonth(prioryear,priormonth,day);SwitchMonth(

41、priormonth);ShowDate.setText(SwitchMonth+","+prioryear);NorthMonthDayYear.setText(">>"+SwitchMonth+","+day+","+prioryear+"<<");key=prioryear+"_"+SwitchMonth+"_"+day;ischange_priornext=true;/Handlenextmonthif("next

42、".equals(Actionmand)if(priormonth<12)priormonth=priormonth+1;elsepriormonth=1;prioryear=prioryear+1;PrintMonth(prioryear,priormonth,day);SwitchMonth(priormonth);ShowDate.setText(SwitchMonth+","+prioryear);NorthMonthDayYear.setText(">>"+SwitchMonth+","+day+

43、","+prioryear+"<<");key=prioryear+"_"+SwitchMonth+"_"+day;ischange_priornext=true;/Handlethe"Gototoday"if("Gototoday".equals(Actionmand)PrintMonth(year,month,day);YearText.setText("");Monthbobox.setSelectedIndex(0);SwitchMon

44、th(month);ShowDate.setText(SwitchMonth+""+","+""+String.valueOf(year);NorthMonthDayYear.setText(">>"+year+SwitchMonth+","+day+","+"<<");key=year+"_"+SwitchMonth+"_"+day;priormonth=month;prioryear=ye

45、ar;ischange=false;/Handlethe"Save"if("Save".equals(Actionmand)WriteRecord();if("Delete".equals(Actionmand)DeleteFile();/HandleJTextFieldeventsif(eAction.getSource()instanceofJTextField)/HandlethequeryAboutActionListenerWay();publicvoidmousePressed(MouseEventeMouse)intda

46、y;try/HandleShowDayseventsif(ischange=false)JTextFieldsource=(JTextField)eMouse.getSource();day=Integer.parseInt(source.getText();if(ischange_priornext=false)NorthMonthDayYear.setText(">>"+SwitchMonth+","+day+","+year+"<<");key=year+"_"+S

47、witchMonth+"_"+day;elseNorthMonthDayYear.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;elseSwitchMonth(priormonth);NorthM

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論