Java日历记事本课程设计报告.docx
- 文档编号:28950643
- 上传时间:2023-07-20
- 格式:DOCX
- 页数:32
- 大小:94.48KB
Java日历记事本课程设计报告.docx
《Java日历记事本课程设计报告.docx》由会员分享,可在线阅读,更多相关《Java日历记事本课程设计报告.docx(32页珍藏版)》请在冰豆网上搜索。
Java日历记事本课程设计报告
Java日历记事本课程设计报告
在设计日历记事本时,需要编写6个JAVA源文件:
、、、、和
效果图如下
.CalendarWindow类
import.*;
import.*;
import.*;
import.*;
publicclassCalendarWindowextendsJFrameimplementsActionListener,MouseListener,FocusListener{
intyear,month,day;
CalendarMessagecalendarMessage;
CalendarPadcalendarPad;
NotePadnotePad;
JTextFieldshowYear,showMonth;
JTextField[]showDay;
CalendarImagecalendarImage;
Stringpicturename;
Clockclock;
JButtonnextYear,previousYear,nextMonth,previousMonth;
JButtonsaveDailyRecord,deleteDailyRecord,readDailyRecord;
JButtongetPicture;
Filedir;
ColorbackColor=;
publicCalendarWindow(){
dir=newFile("./dailyRecord");
();
showDay=newJTextField[42];
for(inti=0;i<;i++){
showDay[i]=newJTextField();
showDay[i].setBackground(backColor);
showDay[i].setLayout(newGridLayout(3,3));
showDay[i].addMouseListener(this);
showDay[i].addFocusListener(this);
}
calendarMessage=newCalendarMessage();
calendarPad=newCalendarPad();
notePad=newNotePad();
Calendarcalendar=();
(newDate());
year=;
month=+1;
day=;
(year);
(month);
(day);
(calendarMessage);
(showDay);
(year,month,day);
();
doMark();
calendarImage=newCalendarImage();
(newFile(""));
clock=newClock();
JSplitPanesplitV1=newJSplitPane,calendarPad,calendarImage);
JSplitPanesplitV2=newJSplitPane,notePad,clock);
JSplitPanesplitH=newJSplitPane,splitV1,splitV2);
add(splitH,;
showYear=newJTextField(""+year,6);
(newFont("TimesRoman",,12));
;
showMonth=newJTextField(""+month,4);
(newFont("TimesRoman",,12));
;
nextYear=newJButton("下年");
previousYear=newJButton("上年");
nextMonth=newJButton("下月");
previousMonth=newJButton("上月");
(this);
(this);
(this);
(this);
JPanelnorth=newJPanel();
(previousYear);
(showYear);
(nextYear);
(previousMonth);
(showMonth);
(nextMonth);
add(north,;
saveDailyRecord=newJButton("保存日志");
deleteDailyRecord=newJButton("删除日志");
readDailyRecord=newJButton("读取日志");
(this);
(this);
(this);
JPanelpSouth=newJPanel();
(saveDailyRecord);
(deleteDailyRecord);
(readDailyRecord);
add(pSouth,;
getPicture=newJButton("选择日历图像");
(this);
(getPicture);
add(pSouth,;
setVisible(true);
setBounds(60,60,660,480);
validate();
setDefaultCloseOperation;
}
publicvoidactionPerformed(ActionEvente){
if()==nextYear){
year++;
(""+year);
(year);
(calendarMessage);
();
(year,month,day);
doMark();
}
elseif()==previousYear){
year--;
(""+year);
(year);
(calendarMessage);
();
(year,month,day);
doMark();
}
elseif()==nextMonth){
month++;
if(month<1)month=12;
(""+month);
(month);
(calendarMessage);
();
(year,month,day);
doMark();
}
elseif()==previousMonth){
month--;
if(month<1)month=12;
(""+month);
(month);
(calendarMessage);
();
(year,month,day);
doMark();
}
elseif()==showYear){
Strings=().trim();
chara[]=();
booleanboo=false;
for(inti=0;i<;i++)
if(!
(a[i])))
boo=true;
if(boo==true)
(this,"您输入了非法年份","警告",;
elseif(boo==false)
year=(s);
(""+year);
(year);
(calendarMessage);
();
(year,month,day);
doMark();
}
elseif()==saveDailyRecord){
(dir,year,month,day);
doMark();
}
elseif()==deleteDailyRecord){
(dir,year,month,day);
doMark();
}
elseif()==readDailyRecord){
(dir,year,month,day);
}
elseif()==getPicture){
FileDialogfd=newFileDialog(this,"打开文件对话框");
(true);
Stringfileopen=null,filename=null;
fileopen=();
filename=();
(newFile(fileopen,filename));
}
}
publicvoidmousePressed(MouseEvente){
JTextFieldtext=(JTextField)();
Stringstr=().trim();
try{day=(str);
}
catch(NumberFormatExceptionexp){
}
(day);
(year,month,day);
}
publicvoidmouseReleased(MouseEvente){}
publicvoidmouseEntered(MouseEvente){}
publicvoidmouseExited(MouseEvente){}
publicvoidmouseClicked(MouseEvente){}
publicvoidfocusGained(FocusEvente){
Componentcom=(Component)();
;
}
publicvoidfocusLost(FocusEvente){
Componentcom=(Component)();
(backColor);
}
publicvoiddoMark(){
for(inti=0;i<;i++){
showDay[i].removeAll();
Stringstr=showDay[i].getText().trim();
try{
intn=(str);
if(isHaveDailyRecord(n)==true){
JLabelmess=newJLabel("有");
(newFont("TimesRoman",,11));
;
showDay[i].add(mess);
}
}
catch(Exceptionexp){}
}
();
();
}
publicbooleanisHaveDailyRecord(intn){
Stringkey=""+year+""+month+""+n;
String[]dayFile=();
booleanboo=false;
for(intk=0;k<;k++){
if(dayFile[k].equals(key+".txt")){
boo=true;
break;
}
}
returnboo;
}
publicStringgetPicture_address(){
Stringaddress=null;
try{
InputStreamoutOne=newFileInputStream("");
ObjectInputStreamoutTwo=newObjectInputStream(outOne);
try{
address=(String)();
}catch(Exceptionex){
}
();
}catch(IOExceptioneee){
}
if(address!
=null){
returnaddress;
}else{
return"";
}
}
publicvoidactionPerformed1(ActionEvente){
if().equals("更改图片背景")){
FileDialogdia=newFileDialog(this,"选择图片",;
(true);
(true);
if(()!
=null)&&()!
=null)){
try{
FileOutputStreaminOne=newFileOutputStream(
"");
ObjectOutputStreaminTwo=newObjectOutputStream(inOne);
()+());
();
}catch(IOExceptionee){
}
Stringpicturename=getPicture_address();
(newFile(picturename));
}
}
}
publicstaticvoidmain(Stringargs[]){
newCalendarWindow();
}
}
CalendarPad类
import.*;
import.*;
import.*;
importclassCalendarPadextendsJPanel{
intyear,month,day;
CalendarMessagecalendarMessage;
JTextField[]showDay;
JLabeltitle[];
String[]星期={"SUN日","MON一","TUE二","WED三","THU四","FRI四","SAT六"};
JPanelnorth,center;
publicCalendarPad(){
setLayout(newBorderLayout());
north=newJPanel();
(newGridLayout(1,7));
center=newJPanel();
(newGridLayout(6,7));
add(center,);
add(north,);
title=newJLabel[7];
for(intj=0;j<7;j++){
title[j]=newJLabel();
title[j].setFont(newFont("TimesRoman",,12));
title[j].setText(星期[j]);
title[j].setHorizontalAlignment;
title[j].setBorder());
(title[j]);
}
title[0].setForeground;
title[6].setForeground;
}
publicvoidsetShowDayTextField(JTextField[]text){
showDay=text;
for(inti=0;i<;i++){
showDay[i].setFont(newFont("TimesRoman",,15));
showDay[i].setHorizontalAlignment;
showDay[i].setEditable(false);
(showDay[i]);
}
}
publicvoidsetCalendarMessage(CalendarMessagecalendarMessage){
=calendarMessage;
}
publicvoidshowMonthCalendar(){
String[]a=();
for(inti=0;i<42;i++)
showDay[i].setText(a[i]);
validate();
}
}
CalendarMesssage类
importclassCalendarMessage{
intyear=-1,month=-1,day=-1;
publicintgetYear(){
returnyear;
}
publicvoidsetMonth(intmonth){
if(month<=12&&month>=1)
=month;
else
=1;
}
publicintgetMonth(){
returnmonth;
}
publicvoidsetDay(intday){
=day;
}
publicintgetDay(){
returnday;
}
publicString[]getMonthCalendar(){
String[]day=newString[42];
Calendarrili=();
(year,month-1,1);
int星期几=)-1;
intdayAmount=0;
if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
dayAmount=31;
if(month==4||month==6||month==9||month==11)
dayAmount=30;
if(month==2)
if(((year%4==0)&&(year%100!
=0)||year%400==0))
dayAmount=29;
else
dayAmount=28;
for(inti=0;i<星期几;i++)
day[i]="";
for(inti=星期几,n=1;i<星期几+dayAmount;i++){
day[i]=(n);
n++;
}
for(inti=星期几+dayAmount;i<42;i++)
day[i]="";
returnday;
}
publicvoidsetYear(intyear){
=year;
}
}
NotePad类
import.*;
import.*;
import.*;
importclassNotePadextendsJPanelimplementsActionListener{
JTextAreatext;
JTextFieldshowMessage;
JPopupMenumenu;
JMenuItemitemCopy,itemCut,itemPaste,itemClear,btn;
publicNotePad(){
showMessage=newJTextField();
;
(newFont("TimesRoman",,16));
;
;
());
(false);
menu=newJPopupMenu();
itemCopy=newJMenuItem("复制");
itemCut=newJMenuItem("剪切");
itemPaste=newJMenuItem("粘贴");
itemClear=newJMenuItem("清空");
btn=newJMenuItem("字体");
(this);
(this);
(this);
(this);
(this);
(itemCopy);
(itemCut);
(itemPaste);
(itemClear);
(btn);
text=newJTextArea(10,10);
(newMouseAdapter(){
publicvoidmousePressed(MouseEvente){
if()==
(text,(),());
}
});
setLayout(newBorderLayout());
add(showMessage,;
add(newJScrollPane(text),;
}
publicvoidsetShowMessage(intyear,intmonth,intday){
(""+year+"年"+month+"月"+day+"日");
;
(newFont("宋体",,15));
}
publicvoidsave(Filedir,intyear,intmonth,intday){
StringdailyContent=();
StringfileName=""+year+""+month+""+day+".txt";
Stringkey=""+year+""+month+""+day;
String[]dayFile=();
booleanboo=false;
for(intk=0;k<;k++){
if(dayFile[k].startsWith(key)){
boo=true;
break;
}
}
if(boo){
Stringm=""+year+"年"+month+"月"+day
+"已有日志,将新的内容添加到日志吗";
intok=(this,m,"",
;
if(ok=={
try{
Filef=newFile(dir,fileName);
R
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Java 日历 记事本 课程设计 报告