【Java开源代码栏目提醒】:网学会员,鉴于大家对Java开源代码十分关注,论文会员在此为大家搜集整理了“【精品】万年历Java课程设计 - 其它资料”一文,供大家参考学习!
课程设计说明书 NO.1 万年历程序设计1、课程设计的目的 这学期我们
学习了
Java语言,
Java语言是面向对象的开发方法是当今世界最流行的开发方法,是当今流行的
网络编程语言。
它具有面向对象、跨平台、分布应用等特点。
它不仅具有更贴近自然的语义,而且有利于软件的维护和继承。
很多程序开发人员得第一选择。
为了进一步巩固课堂上所学到的知识,深刻把握
Java语言的重要概念及其面向对象的特性,锻炼学生熟练的应用面向对象的思想和设计方法解决实际
问题的能力,开设了
Java程序设计课程设计。
让学生自己动手动脑,将书本上得知识运用到实践当中去,使知识能更好得融会贯通。
为了达到这个目的,我们需要自己动手做一个
Java的课程设计,在这个课程设计里我们需要根据我们手中现有得
软件与知识基础,独立得将它完成,只有这样,我们才能把理论变成实践,将知识真正得做到学以致用。
这次课程设计我主要研究了利用已学的
Java知识编辑一个电子万年历。
通过此次课程设计,来巩固所学
Java语言基本知识,增进
Java语言编辑基本功,掌握JDK、JCreator等开发工具的运用,拓宽
常用类库的应用。
并通过自己动手,自主得学习,对
Java这门课程有更深得了解与认识。
2、设计方案论证2.1课程
设计的基本要求 万年历有很多作用,顾名思义它是一种很方便得计时计年工具,随着科技得发展,我们已经可以通过计算机制作出精美的万年历,通过
计算机制作得万年历不但外观美观,而且功能强大。
通过万年历,我们可以实现很多功能,随意看某年得年份,某年得月份,随意调整某年得某天,并将其显示出来,而且有判断闰年闰月得功能,十分方便。
除此之外,万年历还具有记事本功能,通过记事本功能可以备忘一些事情,备忘得事情可以随意添加在万年历得任意年月日里,如果记录得内容已经不再需要,还可以任意的将记录得内容进行删除,在删除得时候还会提示,是否确定删除,如果是,则程序会将它删除,如果不是,则
系统不会将它删除。
2.2
方案论证 沈 阳 大 学
课程设计说明书 NO.22.2.1 方法 表 1 方法表 方法名 功能 备注(须输入的参数) 初始化各种数 calendar int yearint monthint day 据 SwitchMonth 选择月份 int month PrintMonth 显示月份 int yearint monthint day int startdayint PrintMonthBody 月份体 dayinmonth 判断是否为闰 年 int year 得到开始的天 int yearint month IsLeapYear 得到总天数 int yearint month GetStartDay 得到当月的天 int yearint month GetTotalNumOfDays 数 GetNumOfDaysInMonth WriteRecord 写日记 ReadRecord 看
日记 DeleteFile 删除日记 AboutActionListenerWay 监听路径 actionPerformedActionEvent mousePressed 时间表现 mouseClicked mouseReleased 鼠标点击 mouseEntered 鼠标点击生 mouseExited 点击释放 SaveLog 鼠标进入 Main 鼠标推出 保存日期 唯一的主函数 主函数 沈 阳 大 学 课程设计说明书 NO.32.2.2 程序流程框图 开始 初始化 读、写日期、时间和温度 分离日期时间温度显示值 显示子程序 定时闹铃子程序 日期、时间修改子
程序 农历自动更新子程序 闰月子程 返回 图 1 主程序流程图 图 2 计算阳历程序流程图 沈 阳 大 学 课程设计说明书 NO.4图 3 时间调整程序流程图 沈 阳 大 学 课程设计说明书 NO.52.3 程序说明2.3.1 成员变量见表 2 变量表 表 2 变量表 成员变量描述 变量类型 名称 年、月、日 int Year、month、day 下一年,下一 Int Yearafterquerymonthafterquey 月 开始的时间 Int startday 选择月,天 String SwitchMonth,key,day 改变年 改变月 前一月,前一 年 判断是否改变 Int Changeyearmessage 左、又面板 Int changemonthmessage 年、月 Int priormonth,prioryear 左上角信息标 boolean ischange,ischange_priornext 签 JPanel LeftPaneRightPane 显示月、年标 JLabel YearLabel,MonthLabel 签 JLabel Ask 空格标签 JLabel ShowDate 右上部时间标 JLabel Blank 签 JLabel NorthMonthDayYear 星期标签数组 JLabel TopBarTitle 月份下拉
列表 JComboBox MonthCombobox 时间确定按钮 JButton Query 保存、删除按 JButton SouthSaveSouthDelete 钮 JButton PriorMonth,NextMonth 前、下一月按 JTextArea CenterText 钮 String week 文本区 JTextField ShowDays 星期字符串数 JTextField YearText 组 显示天的文本 区 输入年的文本 区 沈 阳 大 学 课程设计说明书 NO.62.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 JFrame implements ActionListenerMouseListener int yearmonthday int yearafterquerymonthafterquery int startday String SwitchMonth String key int changeyearmessage int changemonthmessage int priormonth int prioryear boolean ischangefalse boolean ischange_priornextfalse private JPanel LeftPaneRightPane //Left sub private 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 TopBarTitlenew JLabel7 private JButton ToToday private JButton Query private String weekquotSUNquotquotMONquotquotTUEquotquotWEDquotquotTHUquotquotFRIquotquotSATquot //right sub private JLabel NorthMonthDayYear 沈 阳 大 学 课程设计说明书 NO.7private JTextArea CenterTextprivate JButton SouthSaveSouthDeleteprivate JButton PriorMonthprivate JButton NextMonthpublic calendarint yearint monthint daysetTitlequotMy CalendarampTextbookquot//the layout about left of jpaneLeftPane new JPanelJPanel LeftCenter new JPanelJPanel LeftNorth new JPanel//JPanel LeftSouth new JPanelLeftPane.setLayoutnew BorderLayoutLeftPane.addLeftNorthBorderLayout.NORTHLeftPane.addLeftCenterBorderLayout.CENTERLeftPane.addToToday new JButtonquotGo to todayquotnewImageIconquot../images/Handle.gifquotBorderLayout.SOUTHToToday.setBackgroundColor.cyanToToday.addActionListenerthisLeftPane.validate//the layout of LeftPane//LeftPane_NorthLeftNorth.setLayoutnew GridLayout310-2LeftNorth.addAsk new JLabelquot Plese input the informations which you want query:quotJPanel North new JPanelnew FlowLayout080LeftNorth.addNorthNorth.addYearLabelnew JLabelquotYear:quotNorth.addYearText new JTextField4YearText.setBackgroundColor.getHSBColor302050YearText.setForegroundColor.blueYearText.setFontnew FontquotTimesRomanquotFont.BOLD17YearText.addActionListenerthisYearText.setFocusabletrueNorth.addBlanknew JLabelquot quotNorth.addMonthLabel new JLabelquotMonth:quotNorth.addMonthCombobox new JComboBox//add month to monthcomboboxforint i1ilt12iMonthCombobox.addItemnew Integeri 沈 阳 大 学 课程设计说明书 NO.8 //Switch the month MonthCombobox.setForegroundColor.blue MonthCombobox.setFontnew FontquotTimesRomanquotFont.BOLD12 North.addBlanknew JLabelquot quot North.addQuerynew JButtonquotQueryquot Query.setForegroundColor.blue Query.addActionListenerthis JPanel North2new JPanelnew FlowLayout LeftNorth.addNorth2 North2.addPriorMonthnew JButtonnew ImageIconquot../images/prior.gifquot PriorMonth.addActionListenerthis PriorMonth.setActionCommandquotpriorquot priormonthmonth prioryearyear SwitchMonthmonth North2.addShowDate new JLabelSwitchMonthquot quotquotquotquotquotString.valueOfyearSwingConstants.CENTER ShowDate.setForegroundColor.blue ShowDate.setFontnew FontquotTimesRomanquotFont.BOLD14 North2.addNextMonthnew JButtonnew ImageIconquot../images/next.gifquot NextMonth.addActionListenerthis NextMonth.setActionCommandquotnextquot //LeftPane_Center LeftCenter.setLayoutnew GridLayout77 //print title forint i0ilt7i TopBarTitleinew JLabel TopBarTitlei.setTextweeki TopBarTitlei.setForegroundColor.darkGray TopBarTitlei.setHorizontalAlignment0 TopBarTitlei.setBackgroundColor.MAGENTA TopBarTitlei.setBorderBorderFactory.createRaisedBevelBorder LeftCenter.addTopBarTitlei //print screen and add listener forint i0ilt42i ShowDaysinew JTextField ShowDaysi.addMouseListenerthis ShowDaysi.setEditablefalse 沈 阳 大 学 课程设计说明书 NO.9LeftCenter.addShowDaysi//print the body of monthPrintMonthyearmonthday//the layout about right of jpaneRightPane new JPanelnew BorderLayoutJPanel RightCenter new JPanelJPanel RightNorth new JPanelJPanel RightSouth new JPanelnew FlowLayoutRightPane.addRightNorthBorderLayout.NORTHRightPane.addRightCenterBorderLayout.CENTERRightPane.addRightSouthBorderLayout.SOUTHRightNorth.addNorthMonthDayYearnewJLabelquotgtgtquotyearquotquotSwitchMonthquotquotdayquotltltquotkeyyearquot_quotSwitchMonthquot_quotdayNorthMonthDayYear.setForegroundColor.blueNorthMonthDayYear.setFontnew FontquotTimesRomanquotFont.BOLD17RightCenter.addCenterTextnew JTextAreaquotplease write todays things.quotCenterText.setLineWraptrueCenterText.setSelectedTextColorColor.blue//CenterText.addActionListenerthisRightSouth.addSouthSavenew JButtonquot Save quotSouthSave.setBackgroundColor.cyanSouthSave.addActionListenerthisSouthSave.setActionCommandquotSavequotRightSouth.addSouthDeletenew JButtonquot Delete quotSouthDelete.setBackgroundColor.cyanSouthDelete.addActionListenerthisSouthDelete.setActionCommandquotDeletequotthis.year yearthis.month monththis.day day///add container to put LeftPane and RightPaneContainer congetContentPaneJSplitPane splitnewJSplitPaneJSplitPane.HORIZONTAL_SPLITRightPaneLeftPane//gai biancon.addsplitBorderLayout.CENTERcon.validate//add CenterPane to notepad//CenterPane initializesetFontnew FontquotTimes New RomanquotFont.PLAIN12 沈 阳 大 学 课程设计说明书 NO.10JScrollPane scrollpane new JScrollPaneCenterTextscrollpane.setPreferredSizenew Dimension220250RightCenter.addscrollpane//init randomaccessfile//switch the month in englishpublic void SwitchMonthint monthswitchmonthcase 1:SwitchMonthquotJanquotbreakcase 2:SwitchMonthquotFebquotbreakcase 3:SwitchMonthquotMarquotbreakcase 4:SwitchMonthquotAprquotbreakcase 5:SwitchMonthquotMayquotbreakcase 6:SwitchMonthquotJunquotbreakcase 7:SwitchMonthquotJulquotbreakcase 8:SwitchMonthquotAugquotbreakcase 9:SwitchMonthquotSepquotbreakcase 10:SwitchMonthquotQctquotbreakcase 11:SwitchMonthquotNovquotbreakcase 12:SwitchMonthquotDecquotbreak//print the body of the monthpublic void PrintMonthint yearint monthint day//Get start day of the week for the first date in the monthint startday GetStartDayyearmonth 沈 阳 大 学 课程设计说明书 NO.11//Get number of days in the monthint dayinmonth GetNumOfDaysInMonthyearmonth//Print header//PrintTitleAndScreen//Print bodyPrintMonthBodystartdaydayinmonthday//PrintMonthint yearint monthint days burdenpublic void PrintMonthint yearint month//Get start day of the week for the first date in the monthint startday GetStartDayyearmonth//Get number of days in the monthint dayinmonth GetNumOfDaysInMonthyearmonth//Print header//Print bodyPrintMonthBodystartdaydayinmonth//PrintMonthBodyint startdayint dayinmonthint days burdenpublic void PrintMonthBodyint startdayint dayinmonthforint istartdayn1iltstartdaydayinmonthiShowDaysi.setTextquotquotnShowDaysi.setHorizontalAlignment0//let centerifndayShowDaysi.setForegroundColor.greenShowDaysi.setFontnew FontquotTimesRomanquotFont.BOLD20ShowDaysi.setBackgroundColor.DARK_GRAYelseShowDaysi.setFontnew FontquotTimesRomanquotFont.BOLD12ShowDaysi.setForegroundColor.whiteShowDaysi.setBackgroundColor.DARK_GRAYnforint i0iltstartdayi 沈 阳 大 学 课程设计说明书 NO.12ShowDaysi.setTextquotquotShowDaysi.setBackgroundColor.DARK_GRAYforint istartdaydayinmonthilt42iShowDaysi.setTextquotquotShowDaysi.setBackgroundColor.DARK_GRAY//judge leapyear is or notpublic boolean IsLeapYearint yearifyear4000year40ampampyear1000return trueelsereturn false//judge the start day of a monthpublic int GetStartDayint yearint month//get total number of day since1/1/0000int startday0001-32768long totalnumofdaysGetTotalNumOfDaysyearmonth//return the start dayreturn inttotalnumofdaysstartday00017//judge the days of a yearpublic long GetTotalNumOfDaysint yearint monthlong total0//get the total days from -32767 to yearforint i-32767iltyeariifIsLeapYearitotaltotal366elsetotaltotal365//Add days from jan to the month prior to the calendar mo.