万年历Java课程设计.docx

上传人:小飞机 文档编号:4929863 上传时间:2023-05-24 格式:DOCX 页数:23 大小:396.63KB
返回 下载 相关 举报
万年历Java课程设计.docx_第1页
第1页 / 共23页
万年历Java课程设计.docx_第2页
第2页 / 共23页
万年历Java课程设计.docx_第3页
第3页 / 共23页
万年历Java课程设计.docx_第4页
第4页 / 共23页
万年历Java课程设计.docx_第5页
第5页 / 共23页
亲,该文档总共23页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《万年历Java课程设计.docx》由会员分享,可在线阅读,更多相关《万年历Java课程设计.docx(23页珍藏版)》请在三一办公上搜索。

1、万年历程序设计1、课程设计的目的这学期我们学习了Java语言,Java语言是面向对象的开发方法是当今世界最流行的 开发方法,是当今流行的网络编程语言。它具有面向对象、跨平台、分布应用等特点。 它不仅具有更贴近自然的语义,而且有利于软件的维护和继承。很多程序开发人员得第 一选择。为了进一步巩固课堂上所学到的知识,深刻把握J ava语言的重要概念及其面向对象 的特性,锻炼学生熟练的应用面向对象的思想和设计方法解决实际问题的能力,开设了 Java程序设计课程设计。让学生自己动手动脑,将书本上得知识运用到实践当中去,使 知识能更好得融会贯通。为了达到这个目的,我们需要自己动手做一个Java的课程设计,

2、在这个课程设计里 我们需要根据我们手中现有得软件与知识基础,独立得将它完成,只有这样,我们才能 把理论变成实践,将知识真正得做到学以致用。这次课程设计我主要研究了利用已学的J ava知识编辑一个电子万年历。通过此次课 程设计,来巩固所学Java语言基本知识,增进Java语言编辑基本功,掌握JDK、JCreator 等开发工具的运用,拓宽常用类库的应用。并通过自己动手,自主得学习,对Java这门 课程有更深得了解与认识。2、设计方案论证2.1课程设计的基本要求万年历有很多作用,顾名思义它是一种很方便得计时计年工具,随着科技得发展, 我们已经可以通过计算机制作出精美的万年历,通过计算机制作得万年历

3、不但外观美 观,而且功能强大。通过万年历,我们可以实现很多功能,随意看某年得年份,某年得月份,随意调整 某年得某天,并将其显示出来,而且有判断闰年闰月得功能,十分方便。除此之外,万年历还具有记事本功能,通过记事本功能可以备忘一些事情,备忘得 事情可以随意添加在万年历得任意年月日里,如果记录得内容已经不再需要,还可以任 意的将记录得内容进行删除,在删除得时候还会提示,是否确定删除,如果是,则程序 会将它删除,如果不是,则系统不会将它删除。2.2方案论证2.2.1方法表1方法表方法名功能备注(须输入的参数)calendar初始化各种数 据int year,int month,int daySwit

4、chMonth选择月份int monthPrintMonth显示月份int year,int month,int dayPrintMonthBody月份体intstartday,intdayinmonthIsLeapYearGetStartDayGetTotalNumOfDays判断是否为闰年得到开始的天得到总天数得到当月的天数int yearint year,int monthint year,int monthint year,int monthGetNumOfDaysInMonthWriteRecordReadRecord写日记看日记 删除日记 监听路径DeleteFileAboutAc

5、tionListenerWay actionPerformed(ActionEvent) mousePressed时间表现mouseClickedmouseReleased mouseEntered mouseExited鼠标点击 鼠标点击生 点击释放SaveLog鼠标进入Main鼠标推出 保存日期 主函数唯一的主函数2.2.2程序流程框图图1主程序流程图蟹阳庄怠天数乂有ir月加11总天教中3)nA读月天数忌.天数中力口入号-一,.十算啊历天数堵束,恙天数中的数昭 为当tir曰期在阳而中崖第几天图2计算阳历程序流程图图3时间调整程序流程图2.3程序说明2.3.1成员变量见表2变量表表2变量表成

6、员变量描述变量类型名称年、月、日下一年,下一 月开始的时间选择月,天改变年 改变月r-t刖一月,刖一 年判断是否改变 左、又面板 年、月左上角信息标 签显示月、年标 签空格标签 右上部时间标 签星期标签数组 月份下拉列表 时间确定按钮 保存、删除按 钮前、下一月按 钮文本区星期字符串数 组显示天的文本 区输入年的文本 区intIntIntStringInt Int Int boolean JPanel JLabel JLabel JLabel JLabel JLabel JLabel JComboBox JButton JButton JButton JTextArea String JTex

7、tField JTextFieldYear、month、dayYearafterquery,monthafterqueystartdaySwitchMonth, key, dayChangeyearmessage changemonthmessage priormonth, prioryear ischange, ischange_priornextLeftPane,RightPaneYearLabel, MonthLabelAskShowDateBlankNorthMonthDayYearTopBarTitle MonthComboboxQuerySouthSave,SouthDeleteP

8、riorMonth, NextMonth CenterText weekShowDays YearText2. 4程序源代码import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.event.*;import javax.swing.border.*;import java.util.Calendar;import java.util.*;import java.io.*;import java.io.IOException;public class calendar extends J

9、Frameimplements ActionListener,MouseListenerint year,month,day;int yearafterquery,monthafterquery;int startday;String SwitchMonth;String key;int changeyearmessage;int changemonthmessage;int priormonth;int prioryear;boolean ischange=false;boolean ischange_priornext=false;private JPanel LeftPane,Right

10、Pane;/Left subprivate JLabel YearLabel;private JLabel MonthLabel;private JComboBox MonthCombobox;private JTextField ShowDays= new JTextField42;private JTextField YearText;private JLabel Ask;private JLabel ShowDate;private JLabel Blank;private JLabel TopBarTitle=new JLabel7;private JButton ToToday;pr

11、ivate JButton Query;privateString week=SUN,MON,TUE,WED,THU,FRI,SAT;/right subprivate JLabel NorthMonthDayYear;private JTextArea CenterText;private JButton SouthSave,SouthDelete;private JButton PriorMonth;private JButton NextMonth;public calendar(int year,int month,int day)setTitle(My Calendar&Textbo

12、ok);/the layout about left of jpaneLeftPane = new JPanel();JPanel LeftCenter = new JPanel();JPanel LeftNorth = new JPanel();/JPanel LeftSouth = new JPanel();LeftPane.setLayout(new BorderLayout();LeftPane.add(LeftNorth,BorderLayout.NORTH);LeftPane.add(LeftCenter,BorderLayout.CENTER);LeftPane.add(ToTo

13、day = new JButton(Go to today,newImageIcon(./images/Handle.gif),BorderLayout.SOUTH);ToToday.setBackground(Color.cyan);ToToday.addActionListener(this);LeftPane.validate();/the layout of LeftPane/LeftPane_NorthLeftNorth.setLayout(new GridLayout(3,1,0,-2);LeftNorth.add(Ask = new JLabel( Plese input the

14、 informations which you want query:);JPanel North = new JPanel(new FlowLayout(0,8,0);LeftNorth.add(North);North.add(YearLabel=new JLabel(Year:);North.add(YearText = new JTextField(4);YearText.setBackground(Color.getHSBColor(30,20,50);YearText.setForeground(Color.blue);YearText.setFont(new Font(Times

15、Roman,Font.BOLD,17);YearText.addActionListener(this);YearText.setFocusable(true);North.add(Blank=new JLabel( );North.add(MonthLabel = new JLabel(Month:);North.add(MonthCombobox = new JComboBox();/add month to monthcomboboxfor(int i=1;i=12;i+)MonthCombobox.addItem(new Integer(i);/Switch the monthMont

16、hCombobox.setForeground(Color.blue);MonthCombobox.setFont(new Font(TimesRoman,Font.BOLD,12);North.add(Blank=new JLabel( );North.add(Query=new JButton(Query);Query.setForeground(Color.blue);Query.addActionListener(this);JPanel North2=new JPanel(new FlowLayout();LeftNorth.add(North2);North2.add(PriorM

17、onth=new JButton(new ImageIcon(./images/prior.g if);PriorMonth.addActionListener(this);PriorMonth.setActionCommand(prior);priormonth=month;prioryear=year;SwitchMonth(month);North2.add(ShowDate = new JLabel(SwitchMonth+ +,+String.valueOf(year),SwingConstants.CENTER);ShowDate.setForeground(Color.blue)

18、;ShowDate.setFont(new Font(TimesRoman,Font.BOLD,14);North2.add(NextMonth=new JButton(new ImageIcon(./images/next.gif);NextMonth.addActionListener(this);NextMonth.setActionCommand(next);/LeftPane_CenterLeftCenter.setLayout(new GridLayout(7,7);/print titlefor(int i=0;i7;i+)TopBarTitlei=new JLabel();To

19、pBarTitlei.setText(weeki);TopBarTitlei.setForeground(Color.darkGray);TopBarTitlei.setHorizontalAlignment(0);TopBarTitlei.setBackground(Color.MAGENTA );TopBarTitlei.setBorder(BorderFactory.createRaisedBevelBorder();LeftCenter.add(TopBarTitlei);/print screen and add listenerfor(int i=0;i+year+,+Switch

20、Month+,+day+);key=year+_+SwitchMonth+_+day;NorthMonthDayYear.setForeground(Color.blue);NorthMonthDayYear.setFont(new Font(TimesRoman,Font.BOLD,17);RightCenter.add(CenterText=new JTextArea(please write todays things.);CenterText.setLineWrap(true);CenterText.setSelectedTextColor(Color.blue);/CenterTex

21、t.addActionListener(this);RightSouth.add(SouthSave=new JButton(Save);SouthSave.setBackground(Color.cyan);SouthSave.addActionListener(this);SouthSave.setActionCommand(Save);RightSouth.add(SouthDelete=new JButton( Delete );SouthDelete.setBackground(Color.cyan);SouthDelete.addActionListener(this);South

22、Delete.setActionCommand(Delete);this.year = year;this.month = month;this.day = day;/add container to put LeftPane and RightPaneContainer con=getContentPane();JSplitPanesplit=newJSplitPane(JSplitPane.HORIZONTAL_SPLIT,RightPane,LeftPane);/gai biancon.add(split,BorderLayout.CENTER);con.validate();/add

23、CenterPane to notepad/CenterPane initializesetFont(new Font(Times New Roman,Font.PLAIN,12);JScrollPane scrollpane = new JScrollPane(CenterText); scrollpane.setPreferredSize(new Dimension(220,250);RightCenter.add(scrollpane);/init randomaccessfile/switch the month in englishpublic void SwitchMonth(in

24、t month)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:SwitchMonth=Jun”;break;case 7:SwitchMonth=Jul”;break;case 8:SwitchMonth=Aug;break;case 9:SwitchMonth=Sep”;break;case 10:Swi

25、tchMonth=Qct;break;case 11:SwitchMonth=Nov;break;case 12:SwitchMonth=Dec”;break;/print the body of the monthpublic void PrintMonth(int year,int month,int day)/Get start day of the week for the first date in the month int startday = GetStartDay(year,month);/Get number of days in the monthint dayinmon

26、th = GetNumOfDaysInMonth(year,month);/Print header/PrintTitleAndScreen();/Print bodyPrintMonthBody(startday,dayinmonth,day);/PrintMonth(int year,int month,int day)s burdenpublic void PrintMonth(int year,int month)/Get start day of the week for the first date in the month int startday = GetStartDay(y

27、ear,month);/Get number of days in the monthint dayinmonth = GetNumOfDaysInMonth(year,month);/Print header/Print bodyPrintMonthBody(startday,dayinmonth);/PrintMonthBody(int startday,int dayinmonth,int day)s burden public void PrintMonthBody(int startday,int dayinmonth) for(int i=startday,n=1;istartda

28、y+dayinmonth;i+)ShowDaysi.setText(+n);ShowDaysi.setHorizontalAlignment(0);/let center if(n=day) ShowDaysi.setForeground(Color.green);ShowDaysi.setFont(new Font(TimesRoman,Font.BOLD,20);ShowDaysi.setBackground(Color.DARK_GRAY);elseShowDaysi.setFont(new Font(TimesRoman,Font.BOLD,12);ShowDaysi.setForeg

29、round(Color.white);ShowDaysi.setBackground(Color.DARK_GRAY);n+;for(int i=0;istartday;i+)ShowDaysi.setText();ShowDaysi.setBackground(Color.DARK_GRAY);for(int i=startday+dayinmonth;i42;i+)ShowDaysi.setText();ShowDaysi.setBackground(Color.DARK_GRAY);/judge leapyear is or notpublic boolean IsLeapYear(in

30、t year)if(year%400=0)|(year%4=0&year%100!=0)return true;elsereturn false;/judge the start day of a monthpublic int GetStartDay(int year,int month)/get total number of day since1/1/0000int startday0001=-32768;long totalnumofdays=GetTotalNumOfDays(year,month);/return the start dayreturn (int)(totalnum

31、ofdays+startday0001)%7);/judge the days of a yearpublic long GetTotalNumOfDays(int year,int month)long total=0;/get the total days from -32767 to yearfor(int i=-32767;iyear;i+)if(IsLeapYear(i)total=total+366;elsetotal=total+365;/Add days from jan to the month prior to the calendar month for(int i=1;

32、imonth;i+)total=total+GetNumOfDaysInMonth(year,i);return total;/judge the days of a monthpublic int GetNumOfDaysInMonth(int year,int month)if(month=1 | month=3 | month=5 | month=7 | month=8 | month=10 |month=12)return 31;if(month=4 | month=6 | month=9 | month=11)return 30;if(month=2)if(IsLeapYear(ye

33、ar)return 29;elsereturn 28;return 0;public void WriteRecord()String content;content=CenterText.getText();int n=content.length();char contentarr=new charn;tryint i=0;for(i=0;in;i+)contentarri=content.charAt(i);File Diary = new File(Diary);Diary.mkdir();File myfile=new File(Diary+key+.txt);FileWriter

34、Record=new FileWriter(myfile);for(i=0;i1)priormonth=priormonth-1;elsepriormonth=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;/Handle next monthif(next”.equals(ActionCommand)if(priormonth

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 生活休闲 > 在线阅读


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号