java课程设计报告实用万年历记事本.docx

上传人:b****8 文档编号:9319433 上传时间:2023-02-04 格式:DOCX 页数:23 大小:160.19KB
下载 相关 举报
java课程设计报告实用万年历记事本.docx_第1页
第1页 / 共23页
java课程设计报告实用万年历记事本.docx_第2页
第2页 / 共23页
java课程设计报告实用万年历记事本.docx_第3页
第3页 / 共23页
java课程设计报告实用万年历记事本.docx_第4页
第4页 / 共23页
java课程设计报告实用万年历记事本.docx_第5页
第5页 / 共23页
点击查看更多>>
下载资源
资源描述

java课程设计报告实用万年历记事本.docx

《java课程设计报告实用万年历记事本.docx》由会员分享,可在线阅读,更多相关《java课程设计报告实用万年历记事本.docx(23页珍藏版)》请在冰豆网上搜索。

java课程设计报告实用万年历记事本.docx

java课程设计报告实用万年历记事本

java课程设计报告---实用万年历记事本

Java应用技术实践报告

题目实用万年历记事本

起讫日期

所在院系

学生姓名专业

班级学号

指导教师职称

所在单位

2010年1月11日

一(总体设计

NotePad1(类之间的关系如图1-1所示。

CalendarWindow

Clock

CalendarImagCalendarMessCalendarPad

eag

e

图1-1类之间的关系2(java源文件及其功能如表1-1所示。

表1-1java源文件及其功能序文件名主要功能备注号

CalendarWindow.jav创建实用万年历记事本程序的主窗含有main方法1a口

CalendarMessage.ja该文件用来刻画和“日期”有关的数2va据

该文件负责显示和修改3CalendarPad.javaCalendarMessage对象中的日期数据

该文件负责提供编辑、读取、保存和4NotePad.java删除日志的

该文件负责绘制图像5CalendarImage.java

该文件负责显示时钟6Clock.java

-1-

二(详细设计

1(CalendarWindow

(1)成员变量

主要成员变量(属性)

成员变量描述变量类型名称

年、月、日Year,month,dayInt

显示日期showDayJTextField[]

日历对象calendarPadCalendarPad

日志对象notepadNotePad

月JTextField[]ShowMonth

年JTextField[]ShowYear

图像对象CalendarImagecalendarImage

时钟对象Clockclock

处理日期CalendarMessaecalendarMessae

nextYear、nextMonth、

previousYear、previousMonth、

按钮对象JButtonsaveDailyRecord、

deleteDailyRecord、

readDailyRecord

(2)方法见表

主要方法

方法名功能备注CalendarWindow创建程序主窗口构造方法

doMark对日志日期做出标记focusGained处理FocusListener事件mousePressed处理MouseEvent事件

处理ActionEvent事件actionPerformed接口方法

程序开始运行main

-2-

(3)源代码见文件CalendarWindow

二(CalendarMessage

(1)成员变量见表

表1-4主要成员变量(属性)

成员变量描述变量类型名称

记录日志的年、月、日intyear、month、day

(2)方法见表1-5

表1-5主要方法

方法名功能备注

SetDay、getDay设置、获取日期setMonth/getMonth设置、获取月份setYear、getYear设置、获取年份getMonthCalendar()处理日期数据(3)源代码见文件CalendarMessage.java

importjava.util.Calendar;publicclassCalendarMessage{

intyear=-1,month=-1,day=-1;

publicvoidsetYear(intyear){

this.year=year;

}

publicintgetYear(){

returnyear;

}

publicvoidsetMonth(intmonth){

if(month<=12&&month>=1)

this.month=month;

else

this.month=1;

}

publicintgetMonth(){

returnmonth;

}

publicvoidsetDay(intday){

this.day=day;

}

publicintgetDay(){

returnday;

}

publicString[]getMonthCalendar(){

String[]day=newString[42];

-3-

Calendarrili=Calendar.getInstance();

rili.set(year,month-1,1);//将日历翻到year年month月1日,注意0表示一月...11表示十二月

int星期几=rili.get(Calendar.DAY_OF_WEEK)-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]=String.valueOf(n);

n++;

}

for(inti=星期几+dayAmount;i<42;i++)

day[i]="";

returnday;

}

}

3(CalendarPad

(1)成员变量见表

表1-6主要成员变量(属性)

成员变量描述变量类型名称确定年份、月份、日期的整数year、month、dayInt

calendarPad处理和日期有关的数据CalendarPad

showDay显示日期JTextField

星期String[]

(2)方法见表

表1-7主要方法

方法名功能备注

CalendarPad创建calendarPad对象构造方法

-4-

setShowDayText

Field负责设置showDay数组(JTextField[]

setCalendarMes负责设置sage(CalendarMcalendarMessage对象essage)

showMonthCalen负责显示“日历”dar()

(3)源代码见文件CalendarPad.java

importjavax.swing.*;

importjava.awt.*;

importjava.awt.event.*;

importjava.util.*;

publicclassCalendarPadextendsJPanel{

intyear,month,day;

CalendarMessagecalendarMessage;

JTextField[]showDay;

JLabeltitle[];

String[]星期={"SUN日","MON一","TUE二","WED三","THU四","FRI

五","SAT六"};

JPanelnorth,center;

publicCalendarPad(){

setLayout(newBorderLayout());

north=newJPanel();

north.setLayout(newGridLayout(1,7));

center=newJPanel();

center.setLayout(newGridLayout(6,7));

add(center,BorderLayout.CENTER);

add(north,BorderLayout.NORTH);

title=newJLabel[7];

for(intj=0;j<7;j++){

title[j]=newJLabel();

title[j].setFont(newFont("TimesRoman",Font.BOLD,12));

[j]);title[j].setText(星期

title[j].setHorizontalAlignment(JLabel.CENTER);

title[j].setBorder(BorderFactory.createRaisedBevelBorder());

north.add(title[j]);

}

title[0].setForeground(Color.red);

title[6].setForeground(Color.blue);

}

publicvoidsetShowDayTextField(JTextField[]text){

showDay=text;

for(inti=0;i

showDay[i].setFont(new

Font("TimesRoman",Font.BOLD,15));

showDay[i].setHorizontalAlignment(JTextField.CENTER);

-5-

showDay[i].setEditable(false);

center.add(showDay[i]);

}

}

publicvoidsetCalendarMessage(CalendarMessage

calendarMessage){

this.calendarMessage=calendarMessage;

}

publicvoidshowMonthCalendar(){

String[]a=calendarMessage.getMonthCalendar();

for(inti=0;i<42;i++)

showDay[i].setText(a[i]);

validate();

}

}

4(NotePad

1)成员变量见表1-8(

表1-8主要成员变量(属性)

成员变量描述变量类型名称

JTextArea可编辑多行文本text

显示和日期有关的数据showMessageJTextField

menuJpopupMenu下月,上月

itmeCopy、itmeCut、复制,剪切,粘贴,清空JMenuItemitemPaste、itmeClear

(2)方法见表9

表9主要方法

方法名功能备注

NotePad创建notePad构造方法setShowMessage指定日期数据,显示日(int,int,int)期信息

Save(File,指定日期,保存日志int,int,int)

Save(File,指定日期,删除日志int,int,int)

read(File,int,读取参数日期日志int,int)

(3)源代码见文件NotePad.java

-6-

importjava.awt.*;

importjavax.swing.*;

importjava.io.*;

importjava.awt.event.*;

publicclassNotePadextendsJPanelimplementsActionListener{

JTextAreatext;

JTextFieldshowMessage;

JPopupMenumenu;

JMenuItemitemCopy,itemCut,itemPaste,itemClear;

publicNotePad(){

showMessage=newJTextField();

showMessage.setHorizontalAlignment(JTextField.CENTER);

showMessage.setFont(newFont("TimesRoman",Font.BOLD,16));

showMessage.setForeground(Color.blue);

showMessage.setBackground(Color.pink);

showMessage.setBorder(BorderFactory.createRaisedBevelBorder());

showMessage.setEditable(false);

menu=newJPopupMenu();

itemCopy=newJMenuItem("复制");

itemCut=newJMenuItem("剪切");

itemPaste=newJMenuItem("粘贴");

itemClear=newJMenuItem("清空");

itemCopy.addActionListener(this);

itemCut.addActionListener(this);

itemPaste.addActionListener(this);

itemClear.addActionListener(this);

menu.add(itemCopy);

menu.add(itemCut);

menu.add(itemPaste);

menu.add(itemClear);

text=newJTextArea(10,10);

text.addMouseListener(newMouseAdapter(){

publicvoidmousePressed(MouseEvent

e){

if(e.getModifiers()==InputEvent.BUTTON3_MASK)

menu.show(text,e.getX(),e.getY());

}

});

setLayout(newBorderLayout());

add(showMessage,BorderLayout.NORTH);

add(newJScrollPane(text),BorderLayout.CENTER);

}

publicvoidsetShowMessage(intyear,intmonth,intday){

showMessage.setText(""+year+"年"+month+"月"+day+"日");

}

publicvoidsave(Filedir,intyear,intmonth,intday){

StringdailyContent=text.getText();

StringfileName=""+year+""+month+""+day+".txt";

-7-

Stringkey=""+year+""+month+""+day;

String[]dayFile=dir.list();

booleanboo=false;

for(intk=0;k

if(dayFile[k].startsWith(key)){

boo=true;

break;

}

}

if(boo){

Stringm=""+year+"年"+month+"月"+day+"已有日志,将新的内容添加到日志吗?

";

intok=JOptionPane.showConfirmDialog(this,m,"询问",JOptionPane.YES_NO_OPTION,

JOptionPane.QUESTION_MESSAGE);

if(ok==JOptionPane.YES_OPTION){

try{

Filef=newFile(dir,fileName);

RandomAccessFileout=newRandomAccessFile(f,"rw");

longfileEnd=out.length();

byte[]bb=dailyContent.getBytes();

out.seek(fileEnd);

out.write(bb);

out.close();

}

catch(IOExceptionexp){}

}

}

else{

Stringm=""+year+"年"+month+"月"+day+"还没有日志,保存日志吗?

";

intok=JOptionPane.showConfirmDialog(this,m,"询问",JOptionPane.YES_NO_OPTION,

JOptionPane.QUESTION_MESSAGE);

if(ok==JOptionPane.YES_OPTION){

try{

Filef=newFile(dir,fileName);

RandomAccessFileout=newRandomAccessFile(f,"rw");

longfileEnd=out.length();

byte[]bb=dailyContent.getBytes();

out.write(bb);

out.close();

}

catch(IOExceptionexp){}

}

}

}

publicvoiddelete(Filedir,intyear,intmonth,intday){

Stringkey=""+year+""+month+""+day;

-8-

String[]dayFile=dir.list();

booleanboo=false;

for(intk=0;k

if(dayFile[k].startsWith(key)){

boo=true;

break;

}

}

if(boo){

Stringm="删除"+year+"年"+month+"月"+day+"日的日志吗?

";

intok=JOptionPane.showConfirmDialog(this,m,"询问",JOptionPane.YES_NO_OPTION,

JOptionPane.QUESTION_MESSAGE);

if(ok==JOptionPane.YES_OPTION){

StringfileName=""+year+""+month+""+day+".txt";

FiledeleteFile=newFile(dir,fileName);

deleteFile.delete();

}

}

else{

Stringm=""+year+"年"+month+"月"+day+"无日志记录";

JOptionPane.showMessageDialog(this,m,"提示

",JOptionPane.WARNING_MESSAGE);

}

}

publicvoidread(Filedir,intyear,intmonth,intday){

StringfileName=""+year+""+month+""+day+".txt";

Stringkey=""+year+""+month+""+day;

String[]dayFile=dir.list();

booleanboo=false;

for(intk=0;k

if(dayFile[k].startsWith(key)){

boo=true;

break;

}

}

if(boo){

Stringm=""+year+"年"+month+"月"+day+"有日志,显示日志内容吗?

";

intok=JOptionPane.showConfirmDialog(this,m,"询问",JOptionPane.YES_NO_OPTION,

JOptionPane.QUESTION_MESSAGE);

if(ok==JOptionPane.YES_OPTION){

text.setText(null);

try{

Filef=newFile(dir,fileName);

FileReaderinOne=newFileReader(f);

BufferedReaderinTwo=newBufferedReader(inOne);

Strings=null;

while((s=inTwo.readLine())!

=null)

-9-

text.append(s+"\n");

inOne.close();

inTwo.close();

}

catch(IOExceptionexp){}

}

}

else{

Stringm=""+year+"年"+month+"月"+day+"无日志记录";

JOptionPane.showMessageDialog(this,m,"提示",JOptionPane.WARNING_MESSAGE);

}

}

publicvoidactionPerformed(ActionEvente){

if(e.getSource()==itemCopy)

text.copy();

elseif(e.getSource()==itemCut)

text.cut();

elseif(e.getSource()==itemPaste)

text.paste();

elseif(e.getSource()==itemClear)

text.setText(null);

}

}

5(CalendarImage

1)成员变量见表1-8(

表1-8主要成员变量(属性)

成员变量描述变量类型名称

File存放图像文件的引用imageFile

ImageImage

负责创建image对象Toolkittool

(2)方法见表9

表9主要方法

方法名功能备注CalendarImage创建calendarImage对构造方法()象

负责设置imageFile对setImageFile象,根据imageFile创(File)建image

paintComponent负责绘制image

-10-

(Graphics)

(3)源代码见文件Calendar

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 解决方案 > 学习计划

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1