Java万年历实验报告.docx
《Java万年历实验报告.docx》由会员分享,可在线阅读,更多相关《Java万年历实验报告.docx(32页珍藏版)》请在冰豆网上搜索。
![Java万年历实验报告.docx](https://file1.bdocx.com/fileroot1/2023-2/2/68459cef-5d1d-419f-baec-533419195f1f/68459cef-5d1d-419f-baec-533419195f1f1.gif)
Java万年历实验报告
Java万年历实验报告(总30页)
Java课程实验报告
姓名:
易乃杰
学号:
71
作业要求:
编写一个万年历程序,要求能够查询历史时间,能够添加、查看、删除备忘录。
项目概述:
这个项目是一个简单的Java万年历,可以实现所有年份的公历日期的查询,并且在相应的日期做备忘录,以及可以显示当前的日期以及时间。
程序截图:
具体功能介绍:
(1)万年历查询:
点击图形界面中年份钱下拉框用来调整要查询的年份,点击月份前来调整要查询的月份,然后可以看到这个月的每一天所对应的星期。
(2)Clock功能:
在万年历下面显示当前的年月日时间,相当于一个时钟的功能。
(3)记事本功能。
设计与实现(需要附全部代码,GUI自动生成代码除外):
1类的设计(继承、多态、数据结构):
核心类是CalendarWindow.findPassWordDialog等。
2JavaIO;文件访问
2GUI(用户界面):
点下划线来表示GUI用户界面
6其他功能:
(无)
程序代码:
packageapp;
import;
publicclassClient{
publicstaticvoidmain(String[]args)
{
newCalendarWindow().setVisible(true);
}
}
第一个包
packageaccount;
publicclassAccount{
privateStringname;
privateStringpassWord;
publicAccount(Stringname,StringpassWord)
{
=name;
=passWord;
}
publicStringgetName()
{
returnname;
}
publicvoidsetName(Stringname)
{
=name;
}
publicStringgetPassWord()
{
returnpassWord;
}
publicvoidsetPassWord(StringpassWord)
{
=passWord;
}
@Override
publicStringtoString(){
return"账户"+name+",密码"+passWord;
}
@Override
publicbooleanequals(Objectobj){
if(this==obj)
returntrue;
if(obj==null)
returnfalse;
if(getClass()!
=())
returnfalse;
Accountother=(Account)obj;
if(name==null){
if!
=null)
returnfalse;
}elseif(!
)
returnfalse;
if(passWord==null){
if!
=null)
returnfalse;
}elseif(!
)
returnfalse;
returntrue;
}
}
第二个包(含三个类)
packagecalendar;
publicclassCalendarWindowextendsimplementsObserver{
privateTimetime;
privateintyear;
privateintmonth;
privateintday;
privateWeekweek;
privateDatexcurrent;
privateILoginServiceloginService;
privatebooleanisLogin;
privateIEventServiceeventService;
/**CreatesnewformTimeWindow*/
publicCalendarWindow(){
initComponents();
setLocationRelativeTo(null);
loginService=newLoginService();
eventService=newEventService();
init();
}
privatevoidinit(){
;
()*2+9);
time=newTime();
week=newWeek();
current=();
year=();
month=();
day=();
TimeUnitunit=();
()+"");
()+"");
initTable(current);
initComboBox();
initInfoTextArea(current);
}
oString());
Datextemp=newDatex(year,month,1);
initTable(temp);
initInfoTextArea(temp);
}
privatevoidmonthComboBoxActionPerformedevt){
month=().toString());
Datextemp=newDatex(year,month,1);
initTable(temp);
initInfoTextArea(temp);
}
privatevoidtodayActionPerformedevt){
initTable());
initInfoTextArea(current);
}
privatevoidloginButtonActionPerformedevt){
isLogin=();
if(isLogin){
(this,"已登录,不能重复登录!
");
return;
}
newloginDialog(this,loginService).setVisible(true);
isLogin=();
if(isLogin)
setTitle("万年历(登录状态:
*已登录*)");
}
privatevoideventButtonActionPerformedevt){
if(isLogin)
newEventDialog(this,newDatex(year,month,day),eventService).setVisible(true);
else{
(this,"个人文档已加密,如需访问请先登录!
");
}
}
privatevoidtableMouseClickedevt){
introw=();
intcolumn=();
if(row<0||column<0)
return;
try{
;
(1);
day=(row,column).toString());
initInfoTextArea(newDatex(year,month,day));
}catch(Exceptione){
}
}
packagecalendar;
import;
import;
publicclassCalendarx{
privateDatexcurrent;
publicCalendarx(intyear,intmonth,intday)
{
if(year<=0)
thrownewIllegalArgumentException("输入的年份有误!
");
if(month<=0||month>12)
thrownewIllegalArgumentException("输入的月份有误!
");
if(day<=0||day>(year,month))
thrownewIllegalArgumentException("输入的日期有误!
");
current=newDatex(year,month,day);
}
publicDatexgetcurrent(){
returncurrent;
}
publicDatexgetPreviousDate(){
intyear=();
intmonth=();
intday=();
if()!
=1)
returnnewDatex(year,month,day-1);
if()==1)
returnnewDatex(year-1,12,(year-1,12));
returnnewDatex(year,month-1,(year,month-1));
}
publicDatexgetNextDate(){
intyear=();
intmonth=();
intday=();
if(year,month)!
=day)
returnnewDatex(year,month,day+1);
if(month==12){
returnnewDatex(year+1,1,1);
}
returnnewDatex(year,month+1,1);
}
oString();
Stringinfos=();
try{
if(current).equals(state)
&&(current).equals(infos)){
(false);
return;
}
}catch(Exceptione){
}
intresult=(this,"今日日程已经改变,是否保存",
"关闭信息框",;
if(result=={
(current,state,infos);
(false);
return;
}
}catch(RuntimeExceptione){
setVisible(false);
(parent,"建立"+()
+"日程时出错,请重新建立!
");
}
}
privatevoidstateComboBoxActionPerformedevt){
Stringstate;
try{
state=().toString();
(state);
if(!
().equals("(无)"))
(true);
}catch(RuntimeExceptione){
(parent,"设置日程状态出错!
");
}
}
privatevoidstateItemActionPerformedevt){
Stringstate;
try{
if().equals("(无)"))
(false);
state=(current);
(state);
}catch(RuntimeExceptione){
}
}
privatevoidexitItemActionPerformedevt){
setVisible(false);
}
privatevoidsaveItemActionPerformedevt){
Stringstate;
try{
state=().toString();
Stringinfos=();
(current,state,infos);
}catch(RuntimeExceptione){
setVisible(false);
(parent,"建立"+()
+"日程时出错,请重新建立!
");
}
}
packageevent;
publicclassEventServiceimplementsIEventService{
@Override
publicStringreadAll(Datexdate)throwsRuntimeException{
if(date==null)
thrownewRuntimeException("日期不能为null!
");
Stringresult="";
try{
FileInputStreamin=newFileInputStream("schedules/"
+());
Scannerscanner=newScanner(in);
if())
();
while())
result+=();
();
}catch(IOExceptione){
thrownewRuntimeException("从"+()+"磁盘读信息时出错!
");
}
returnresult;
}
@Override
publicvoidsaveAll(Datexdate,Stringstate,Stringinfo)
throwsRuntimeException{
if(date==null||state==null)
thrownewRuntimeException("日期和日程状态都不能为null!
");
try{
FileWriterout=newFileWriter("schedules/"+());
(state+"\n"+info);
();
}catch(IOExceptione1){
thrownewRuntimeException("信息写入"+()+"磁盘时出错!
");
}
}
@Override
publicStringgetState(Datexdate)throwsRuntimeException{
if(date==null)
thrownewRuntimeException("日期不能为null!
");
Stringresult="";
try{
FileInputStreamin=newFileInputStream("schedules/"
+());
Scannerscanner=newScanner(in);
if())
result=();
();
}catch(IOExceptione){
thrownewRuntimeException("从"+()+"磁盘读信息时出错!
");
}
returnresult;
}
}
packageevent;
import;
publicinterfaceIEventService{
rim();
if()<3||()>15){
("×");
errorNumber1++;
}else{
("√");
errorNumber1--;
}
}catch(Exceptione){
(this,"账户名不合法,此功能无法运行!
");
}
}
privatevoidanswerTextFocusLostevt){
errorNumber2=0;
try{
problem=().toString();
answer=().trim();
if()<=0){
("×");
errorNumber2++;
}else{
("√");
errorNumber2--;
}
}catch(Exceptione){
(this,"问题选择有误,此功能无法运行!
");
}
}
}
packagelogin;
import;
publicinterfaceILoginService{
etVisible(true);
}
privatevoidgainAccountMouseClickedevt){
newRegisterAccountDialog(this,loginService).setVisible(true);
}
privatevoidloginButtonActionPerformedevt){
try{
Stringname=();
if("")){
(this,"账户不能空!
");
return;
}
StringpassWord=());
if("")){
(this,"密码不能空!
");
return;
}
(name,passWord);
(false);
}catch(Exceptione){
(this,());
}
}
}
packagelogin;
import.*;
import;
publicclassLoginServiceimplementsILoginService{
privateStringnewName;
privateStringnewPassWord;
@Override
publicAccountloginAccount(StringnewName,StringnewPassWord)
throwsRuntimeException{
=newName;
=newPassWord;
returnjudgeAccount(newName,newPassWord);
}
privateString[]readInfo(StringfileName,intnum){
String[]result=newString[num];
try{
FileInputStreamin=newFileInputStream(fileName);
Scannerscanner=newScanner(in);
for(inti=0;iif())
result[i]=();
();
}catch(IOExceptione){
thrownewRuntimeException("从"+fileName+"磁盘读信息时出错!
");
}
returnresult;
}
privatevoidwriteInfo(StringfileName,Stringinfo)
{
try{
FileWriterout=newFileWriter(fileName);
(info);
();
}catch(IOExceptione1){
thrownewRuntimeException("信息写入"+fileName+"磁盘时出错!
");
}
}
privateAccountjudgeAccount(StringnewName,StringnewPassWord){
String[]info;
if(newName==null||newPassWord==null)
thrownewRuntimeException("输入的账户和密码都不能为null");
try{
info=readInfo("account",2);
}catch(Exceptione){
thrownewRuntimeException());
}
if(!
info[0].equals(newName))
thrownewRuntimeException("输入的账户名有误!
");
if(!
info[1].equals(newPassWord))
thrownewRuntimeException("输入的密码有误!
");
returnnewAccount(info[0],info[1]);
}
@Override
publicvoidregisterAccount(StringnewName,StringnewPassWord,
Stringproblem,Stringanswer)throwsRuntimeException{
if(newName==null||problem==null||answer==null
||newPassWord==null)
thrownewRuntimeException("输入的账户,密码,问题和答案都不能为null");
try{
writeInfo("account",newName+"\n"+newPassWord+"\n"+problem+"\n"
+answer);
}catch(Exceptione){