您好,欢迎访问三七文档
当前位置:首页 > 电子/通信 > 综合/其它 > Java万年历实验报告
Java课程实验报告姓名:易乃杰学号:2110505171作业要求:编写一个万年历程序,要求能够查询历史时间,能够添加、查看、删除备忘录。项目概述:这个项目是一个简单的Java万年历,可以实现所有年份的公历日期的查询,并且在相应的日期做备忘录,以及可以显示当前的日期以及时间。程序截图:具体功能介绍:(1)万年历查询:点击图形界面中年份钱下拉框用来调整要查询的年份,点击月份前来调整要查询的月份,然后可以看到这个月的每一天所对应的星期。(2)Clock功能:在万年历下面显示当前的年月日时间,相当于一个时钟的功能。(3)记事本功能。设计与实现(需要附全部代码,GUI自动生成代码除外):1类的设计(继承、多态、数据结构):核心类是CalendarWindow.findPassWordDialog等。2JavaIO;文件访问2GUI(用户界面):点下划线来表示GUI用户界面6其他功能:(无)程序代码:packageapp;importcalendar.CalendarWindow;publicclassClient{publicstaticvoidmain(String[]args){newCalendarWindow().setVisible(true);}}第一个包packageaccount;publicclassAccount{privateStringname;privateStringpassWord;publicAccount(Stringname,StringpassWord){this.name=name;this.passWord=passWord;}publicStringgetName(){returnname;}publicvoidsetName(Stringname){this.name=name;}publicStringgetPassWord(){returnpassWord;}publicvoidsetPassWord(StringpassWord){this.passWord=passWord;}@OverridepublicStringtoString(){return账户+name+,密码+passWord;}@Overridepublicbooleanequals(Objectobj){if(this==obj)returntrue;if(obj==null)returnfalse;if(getClass()!=obj.getClass())returnfalse;Accountother=(Account)obj;if(name==null){if(other.name!=null)returnfalse;}elseif(!name.equals(other.name))returnfalse;if(passWord==null){if(other.passWord!=null)returnfalse;}elseif(!passWord.equals(other.passWord))returnfalse;returntrue;}}第二个包(含三个类)packagecalendar;publicclassCalendarWindowextendsjavax.swing.JFrameimplementsObserver{privateTimetime;privateintyear;privateintmonth;privateintday;privateWeekweek;privateDatexcurrent;privateILoginServiceloginService;privatebooleanisLogin;privateIEventServiceeventService;/**CreatesnewformTimeWindow*/publicCalendarWindow(){initComponents();setLocationRelativeTo(null);loginService=newLoginService();eventService=newEventService();init();}privatevoidinit(){table.setGridColor(Color.GREEN);table.setRowHeight(table.getRowHeight()*2+9);time=newTime();week=newWeek();current=time.getSystemDate();year=current.getYear();month=current.getMonth();day=current.getDay();TimeUnitunit=time.getSystemTime();hourText.setText(unit.getHour()+);secondText.setText(unit.getMinute()+);initTable(current);initComboBox();initInfoTextArea(current);}//初始化ComboBoxprivatevoidinitComboBox(){for(inti=0;i=20;i++)yearComboBox.addItem(current.getYear()-10+i);yearComboBox.setSelectedIndex(10);monthComboBox.setSelectedIndex(current.getMonth()-1);}//初始化TextAreaprivatevoidinitInfoTextArea(Datexdate){infoTextArea.setFont(newFont(楷体,Font.BOLD,16));infoTextArea.setLineWrap(true);infoTextArea.setColumns(15);infoTextArea.setRows(8);infoTextArea.setTabSize(10);infoTextArea.setText(【龙年】\n\n+date.toString()+\n+week.getWeek(date)+\n\n\n+【忌讳】:无\n\n\n+【适宜】:无\n\n);}//初始化tableprivatevoidinitTable(Datextoday){DefaultTableModelmodel=newDefaultTableModel();model.addColumn(星期日);model.addColumn(星期一);model.addColumn(星期二);model.addColumn(星期三);model.addColumn(星期四);model.addColumn(星期五);model.addColumn(星期六);Weeksweek1=week.getWeek(newDatex(today.getYear(),today.getMonth(),1));Weeks[]weeks=Weeks.values();intindex=0;intnumx=1;Object[]o=newObject[7];for(inti=weeks.length-1;i=0;i--){if(week1.equals(weeks[i]))index=i;}for(intj=index;j7;j++)o[j]=numx++;model.addRow(o);for(inti=1;i6;i++){o=newObject[7];for(intj=0;j7;j++)if(numx=Uitll.lastday(today.getYear(),today.getMonth()))o[j]=numx++;model.addRow(o);}table.setModel(model);}privatevoidexitItemActionPerformed(java.awt.event.ActionEventevt){System.exit(0);}privatevoidyearComboBoxActionPerformed(java.awt.event.ActionEventevt){year=Integer.valueOf(yearComboBox.getSelectedItem().toString());Datextemp=newDatex(year,month,1);initTable(temp);initInfoTextArea(temp);}privatevoidmonthComboBoxActionPerformed(java.awt.event.ActionEventevt){month=Integer.valueOf(monthComboBox.getSelectedItem().toString());Datextemp=newDatex(year,month,1);initTable(temp);initInfoTextArea(temp);}privatevoidtodayActionPerformed(java.awt.event.ActionEventevt){initTable(time.getSystemDate());initInfoTextArea(current);}privatevoidloginButtonActionPerformed(java.awt.event.ActionEventevt){isLogin=loginService.isOkOfLogin();if(isLogin){JOptionPane.showMessageDialog(this,已登录,不能重复登录!);return;}newloginDialog(this,loginService).setVisible(true);isLogin=loginService.isOkOfLogin();if(isLogin)setTitle(万年历(登录状态:*已登录*));}privatevoideventButtonActionPerformed(java.awt.event.ActionEventevt){if(isLogin)newEventDialog(this,newDatex(year,month,day),eventService).setVisible(true);else{JOptionPane.showMessageDialog(this,个人文档已加密,如需访问请先登录!);}}privatevoidtableMouseClicked(java.awt.event.MouseEventevt){introw=table.getSelectedRow();intcolumn=table.getSelectedColumn();if(row0||column0)return;try{table.setSelectionBackground(Color.WHITE);table.setSelectionMode(1);day=Integer.valueOf(table.getValueAt(row,column).toString());initInfoTextArea(newDatex(year,month,day));}catch(Exceptione){}}packagecalendar;importdateandweek.Datex;importuitl.Uitll;publicclassCalendarx{privateDatexcurrent;publicCalendarx(intyear,intmonth,intday){if(year=0)thrownewIllegalArgumentException(输入的年份有误!);if(month=0||mont
本文标题:Java万年历实验报告
链接地址:https://www.777doc.com/doc-7301097 .html