




已阅读5页,还剩18页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
课程设计说明书 NO.1多功能电子时钟得设计1、课程设计的目的Java语言是面向对象的开发方法是当今世界最流行的开发方法,是当今流行的网络编程语言。它具有面向对象、跨平台、分布应用等特点。它不仅具有更贴近自然的语义,而且有利于软件的维护和继承。很多程序开发人员得第一选择。为了将课堂上得知识掌握得更加透彻,深刻把握Java语言的重要概念及其面向对象的特性,锻炼学生熟练的应用面向对象的思想和设计方法解决实际问题的能力,开设了Java程序设计课程设计。让学生自己动手动脑,将书本上得知识运用到实践当中去,使知识能更好得融会贯通。学习任何知识得目的都是要将它运用到实践中去,所以我们要运用已有的知识,独立得将这个课程设计完成,只有这样,我们才能将知识变成本领,变成属于自己得东西,通过一个学习得学习,我们已经有可一定得Java基础,现在我们就要利用这些基础,来完成课程设计。这次课程设计我主要研究了利用已学的Java知识编辑一个多功能电子时钟。通过此次课程设计,来巩固所学Java语言基本知识,增进Java语言编辑基本功,掌握JDK、JCreator等开发工具的运用,拓宽常用类库的应用。并通过自己动手,自主得学习,对Java这门课程有更深得了解与认识。2、设计方案论证2.1课程设计的基本要求多功能电子时钟是一种多功能得计时工具,它得功能与钟表不同,而是能够将年,月,日通过java程序得到实现,并具有更多的功能,更简洁的外观,更方便的用法,更大的实用价值。通过多功能电子时钟,我们可以实现很多功能,随意看某年得年份,某年得月份,随意调整某年得某天,并将其显示出来,而且有判断闰年闰月得功能,十分方便万年历有很多作用,顾名思义它是一种很方便得计时计年工具,随着科技得发展,我们已经可以通过计算机制作出精美的万年历,通过计算机制作得万年历不但外观美观,而且功能强大。除此之外,万年历还具有记事本功能,通过记事本功能可以备忘一些事情,备忘得事情可以随意添加在万年历得任意年月日里,如果记录得内容已经不再需要,还可以任意的将记录得内容进行删除,在删除得时候还会提示。2.2方案论证 沈 阳 大 学课程设计说明书 NO.22.2.1方法表1 方法表方法名功能备注(须输入的参数)calendar初始化各种数据int year,int month,int daySwitchMonth选择月份int monthPrintMonth显示月份int year,int month,int dayPrintMonthBody月份体int startday,int dayinmonthIsLeapYearGetStartDayGetTotalNumOfDaysGetNumOfDaysInMonthWriteRecordReadRecordDeleteFileAboutActionListenerWayactionPerformed(ActionEvent)mousePressedmouseClickedmouseReleasedmouseEnteredmouseExitedSaveLogMain判断是否为闰年得到开始的天得到总天数得到当月的天数写日记看日记删除日记监听路径时间表现鼠标点击鼠标点击生点击释放鼠标进入鼠标推出保存日期主函数int yearint year,int monthint year,int monthint year,int month唯一的主函数 沈 阳 大 学课程设计说明书 NO.3开始初始化读、写日期、时间和温度分离日期时间温度显示值显示子程序农历自动更新子程序日期、时间修改子程序闰月子程返回定时闹铃子程序2.2.2程序流程框图 图1 主程序流程图图2计算阳历程序流程图 沈 阳 大 学课程设计说明书 NO.4图3时间调整程序流程图 沈 阳 大 学课程设计说明书 NO.52.3程序说明2.3.1成员变量见表2变量表表2变量表成员变量描述变量类型名称年、月、日intYear、month、day下一年,下一月IntYearafterquery,monthafterquey开始的时间Intstartday选择月,天StringSwitchMonth,key,day改变年改变月前一月,前一年判断是否改变左、又面板年、月左上角信息标签显示月、年标签空格标签右上部时间标签星期标签数组月份下拉列表时间确定按钮保存、删除按钮前、下一月按钮文本区星期字符串数组显示天的文本区输入年的文本区IntIntIntbooleanJPanelJLabelJLabelJLabelJLabelJLabelJLabelJComboBoxJButtonJButtonJButtonJTextAreaStringJTextFieldJTextFieldChangeyearmessagechangemonthmessagepriormonth,prioryearischange,ischange_priornextLeftPane,RightPaneYearLabel,MonthLabelAskShowDateBlankNorthMonthDayYearTopBarTitleMonthComboboxQuerySouthSave,SouthDeletePriorMonth,NextMonthCenterTextweekShowDaysYearText 沈 阳 大 学课程设计说明书 NO.624程序源代码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 ActionListener,MouseListener int 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,RightPane; /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 TopBarTitle=new JLabel7; private JButton ToToday; private JButton Query; private String week=SUN,MON,TUE,WED,THU,FRI,SAT;/right subprivate JLabel NorthMonthDayYear; 沈 阳 大 学课程设计说明书 NO.7private JTextArea CenterText; private JButton SouthSave,SouthDelete; private JButton PriorMonth; private JButton NextMonth; public calendar(int year,int month,int day) setTitle(My Calendar&Textbook); /the layout about left of jpane LeftPane = 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(ToToday = new JButton(Go to today,new ImageIcon(./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 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(TimesRoman,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 monthcombobox for(int i=1;i=12;i+) MonthCombobox.addItem(new Integer(i); 沈 阳 大 学课程设计说明书 NO.8/Switch the month MonthCombobox.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(PriorMonth=new JButton(new ImageIcon(./images/prior.gif); 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); 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_Center LeftCenter.setLayout(new GridLayout(7,7); /print title for(int i=0;i7;i+) TopBarTitlei=new JLabel(); TopBarTitlei.setText(weeki); TopBarTitlei.setForeground(Color.darkGray); TopBarTitlei.setHorizontalAlignment(0); TopBarTitlei.setBackground(Color.MAGENTA ); TopBarTitlei.setBorder(BorderFactory.createRaisedBevelBorder();LeftCenter.add(TopBarTitlei); /print screen and add listener for(int i=0;i+year+,+SwitchMonth+,+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);/CenterText.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);SouthDelete.setActionCommand(Delete);this.year = year;this.month = month;this.day = day;/add container to put LeftPane and RightPane Container con=getContentPane(); JSplitPane split=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,RightPane,LeftPane);/gai bian con.add(split,BorderLayout.CENTER); con.validate();/add CenterPane to notepad/CenterPane initializesetFont(new Font(Times New Roman,Font.PLAIN,12); 沈 阳 大 学课程设计说明书 NO.10JScrollPane scrollpane = new JScrollPane(CenterText);scrollpane.setPreferredSize(new Dimension(220,250); RightCenter.add(scrollpane); /init randomaccessfile /switch the month in english public void SwitchMonth(int 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: SwitchMonth=Qct;break; case 11: SwitchMonth=Nov;break; case 12: SwitchMonth=Dec;break; /print the body of the month public 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); 沈 阳 大 学课程设计说明书 NO.11/Get number of days in the month int dayinmonth = GetNumOfDaysInMonth(year,month); /Print header /PrintTitleAndScreen(); /Print body PrintMonthBody(startday,dayinmonth,day); /PrintMonth(int year,int month,int day)s burden public void PrintMonth(int year,int month) /Get start day of the week for the first date in the month int startday = GetStartDay(year,month); /Get number of days in the month int dayinmonth = GetNumOfDaysInMonth(year,month); /Print header /Print body PrintMonthBody(startday,dayinmonth); /PrintMonthBody(int startday,int dayinmonth,int day)s burden public void PrintMonthBody(int startday,int dayinmonth) for(int i=startday,n=1;istartday+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); else ShowDaysi.setFont(new Font(TimesRoman,Font.BOLD,12); ShowDaysi.setForeground(Color.white); ShowDaysi.setBackground(Color.DARK_GRAY); n+; for(int i=0;istartday;i+) 沈 阳 大 学课程设计说明书 NO.12ShowDaysi.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(int 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)(totalnumofdays+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 monthfor(int i=1;imonth;i+)total=total+GetNumOfDaysInMonth(year,i); 沈 阳 大 学课程设计说明书 NO.13return total; /judge the days of a month public 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(year) return 29; else return 28; return 0; public void WriteRecord() String content; content=CenterText.getText(); int n=content.length(); char contentarr=new charn; try int 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 Record=new FileWriter(myfile);for(i=0;i1) priormonth=priormonth-1; else priormonth=12; prioryear=prioryear-1; PrintMonth(prioryear,priormonth,day); SwitchMonth(priormonth); ShowDate.setText(SwitchMonth+ , +prioryear); NorthMonthDayYear.setText(+Sw
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 足疗按摩技术操作试题及答案
- 坐月子饮食禁忌试题及答案
- 2025年罕见病药物研发激励政策与生物制药企业国际化发展报告
- 考点解析-沪科版9年级下册期末试题附完整答案详解(易错题)
- 考点解析-沪科版9年级下册期末试题及完整答案详解【名校卷】
- 2025至2030年中国蛋清粉行业市场供需格局及投资规划建议报告
- 2025版秦都区某小区二手房买卖合同附房屋交易资金监管及结算流程
- 2025年医疗设备制造财务代理与成本控制合同
- 2025年度水利工程项目施工监理分包合同范本
- 2025版文化产业发展三方协议担保服务协议
- 2025年高考英语新课标Ⅱ卷点评及2026备考方向 课件
- 2025广西专业技术人员公需科目培训考试答案
- 智能客服趋势发展白皮书:智能客服预见未来课件
- 大班 语言社会 我升大班啦 课件
- 项目造价咨询计划表
- 幼儿园玩教具操作与活动指导
- 敏捷项目管理实践指南
- 《数据结构》课件(完整版)
- 项目管理(PMBOK)讲义全套
- 友声收银系列电子秤使用说明书
- 《立体裁剪》实训指导书
评论
0/150
提交评论