记事本 java程序设计报告Word下载.docx

上传人:b****6 文档编号:18759466 上传时间:2023-01-01 格式:DOCX 页数:16 大小:139.35KB
下载 相关 举报
记事本 java程序设计报告Word下载.docx_第1页
第1页 / 共16页
记事本 java程序设计报告Word下载.docx_第2页
第2页 / 共16页
记事本 java程序设计报告Word下载.docx_第3页
第3页 / 共16页
记事本 java程序设计报告Word下载.docx_第4页
第4页 / 共16页
记事本 java程序设计报告Word下载.docx_第5页
第5页 / 共16页
点击查看更多>>
下载资源
资源描述

记事本 java程序设计报告Word下载.docx

《记事本 java程序设计报告Word下载.docx》由会员分享,可在线阅读,更多相关《记事本 java程序设计报告Word下载.docx(16页珍藏版)》请在冰豆网上搜索。

记事本 java程序设计报告Word下载.docx

第二部分、我的任务…………………………………………………5页

第三部分、代码和详细注释…………………………………………6页

第四部分、心得体会………………………………………………14页

第一部分、项目整体概述

日历记事本----------带有日程提醒功能的日历。

2.显示信息:

用户可以看到这个月的信息,包括年份、日期等。

点击翻页按钮可以查询前一个月的日期,也可以向后翻页查询下一个月的日期。

同样,可以根据年份查询不同年份的日期。

日期的显示有一些优化,用户不仅可以查询到本月份的信息,还可以根据上个月与下个月的日期填充来方便查询日期和星期。

3.定时提醒:

用户可以针对某一天来添加、删除和编辑这一天的日程提醒信息

当系统时间和提醒时间相吻合时,给出具有提示信息的对话框。

4.查询信息:

用户可以查询到某个月的所有的提示信息。

日历记事本共有4个java源文件。

CalendarPad.java

该java文件生成的类负责创建本日历记事本程序主窗口。

该类含有main方法,程序从该类开始执行。

Year.java

该文件负责创建管理年份的对象。

Month.java

该文件负责创建管理月份的类对象。

NotePad.java

该文件负责创建记事本。

截图:

初始界面

可输入年份查看相应的日历与记事本

第二部分、我的任务

具体任务:

资料查找,汇总及需求分析,负责日历的编写,和板块的布局输出等。

编写大致思路:

我主要负责这个项目中日历的编写和输出显示的一部分。

经过调查自己电脑中的日历记事本和大家纸质的日历记事本,我知道若想完整地显示一个月的信息至少需要一个首先需要一个7*7的网格,要用到GridLayout网格设置语言。

其中每一列的顶层可以称它为title“标题”,也就是显示“星期几”,表头显示这个月所在的年份与月份。

随后对日期进行编号,判断闰平年、大小月等必要的程序。

为了能使用户查找到前一年、下一年,上一月、下一月的内容,还需要设置按钮,让成员变量实现其更改。

总体规划:

主类CanlendarPad

1.成员变量

成员变量描述

变量类型

名称

年、月、日

int

year,month,day

保存日志的散列表

Hanshtable

hanshtable

存放散列表的文件

File

file

显示日期

JtextFile[]

showDay

日历对象

Calendar

日历

记事本对象

NotePad

notepad

Month

负责改变月

Year

负责改变年

2.方法

名称

功能

备注

CalendarPad

创建窗口主程序

构造方法

设置日历牌

设置日立的年份、月份

排列号码

排列月份中的号码

mousePressed

处理MouseEvent事件

接口方法

main

程序开始运行

第三部分、源代码及详细注释:

CalendarPad

importjava.util.Calendar;

//写的Calendar类里面导入这个包下的所有类库

publicclassCalendarPadextendsJFrameimplementsMouseListener

{//定义CalendarPad类继承JFrame父类的属性MouseListener鼠标监听

intyear,month,day;

//定义年月日

Hashtablehashtable;

//用来保存日志的散列哈希表

Filefile;

//存在哈希表中的文件

JTextFieldshowDay[];

//每天是7X7的一个小格子单元

JLabeltitle[];

//用来创建日历牌中的表格属性“星期几”

Calendar日历;

//定义“日历”方法是calendar

int星期几;

//整形定义“星期几”方法

NotePadnotepad=null;

//日记本对象,初值为空

Month负责改变月;

//定义“负责改变月”方法

Year负责改变年;

//定义“负责改变年”方法

String星期[]={"

星期日"

"

星期一"

星期二"

星期三"

星期四"

星期五"

星期六"

};

JPanelleftPanel,rightPanel;

//界面设计,左边是日历,右面为记事本

publicCalendarPad(intyear,intmonth,intday)//在CalendarPad类中定义年月日

{

getContentPane().setBackground(newColor(255,228,225));

//初始化一个容器,设置颜色值为(255,,228,225)

setBackground(newColor(255,250,250));

//颜色设置

setFont(newFont("

微软雅黑"

Font.BOLD,12));

//字体设置

setForeground(newColor(70,130,180));

setTitle("

"

);

leftPanel=newJPanel();

//传入一个布局对象作为参数来创建左边的面板

JPanelleftCenter=newJPanel();

JPanelleftNorth=newJPanel();

leftCenter.setLayout(newGridLayout(7,7));

//设置窗口,为7*7的网格,参数说明(行数,列数)

rightPanel=newJPanel();

//设置右侧面板

this.year=year;

this.month=month;

this.day=day;

负责改变年=newYear(this);

负责改变年.setFont(newFont("

//设置字体

负责改变年.setForeground(newColor(65,105,225));

//设置前景色

负责改变年.setYear(year);

//调用方法

负责改变月=newMonth(this);

负责改变月.setFont(newFont("

负责改变月.setForeground(newColor(65,105,225));

负责改变月.setMonth(month);

title=newJLabel[7];

//“星期几”标题,有7个

showDay=newJTextField[42];

//显示日期的文件有42个(对应42个网格)

for(intj=0;

j<

7;

j++)//标题的写入,周日到周一

title[j]=newJLabel();

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

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

//创建边框

leftCenter.add(title[j]);

}

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

//设置周日为红色

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

//设置周六为蓝色

for(inti=0;

i<

42;

i++)//日期写入

showDay[i]=newJTextField();

showDay[i].addMouseListener(this);

showDay[i].setEditable(false);

leftCenter.add(showDay[i]);

}

日历=Calendar.getInstance();

//年份月份的查询

Boxbox=Box.createHorizontalBox();

box.add(负责改变年);

box.add(负责改变月);

leftNorth.add(box);

leftPanel.setLayout(newBorderLayout());

leftPanel.add(leftNorth,BorderLayout.NORTH);

//上方的边界

leftPanel.add(leftCenter,BorderLayout.CENTER);

//中间

Labellabel=newLabel("

请在年份输入框输入所查年份,按回车确定。

负数为公元前"

label.setBackground(UIManager.getColor("

ScrollBar.foreground"

));

//具体设置

label.setFont(newFont("

黑体"

Font.BOLD,13));

label.setForeground(newColor(204,0,0));

leftPanel.add(label,

BorderLayout.SOUTH);

//下方的边界

leftPanel.validate();

Containercon=getContentPane();

JSplitPanesplit=newJSplitPane(JSplitPane.HORIZONTAL_SPLIT,

leftPanel,rightPanel);

con.add(split,BorderLayout.CENTER);

con.validate();

hashtable=newHashtable();

//初始化哈希表

file=newFile("

日历记事本.txt"

//初始化文件

if(!

file.exists())

try{

FileOutputStreamout=newFileOutputStream(file);

ObjectOutputStreamobjectOut=newObjectOutputStream(out);

objectOut.writeObject(hashtable);

objectOut.close();

out.close();

catch(IOExceptione)//捕获输入输出异常

notepad=newNotePad(this);

//调用notepad的数据

rightPanel.add(notepad);

设置日历牌(year,month);

addWindowListener(newWindowAdapter()

{publicvoidwindowClosing(WindowEvente)

System.exit(0);

});

setVisible(true);

setBounds(100,50,612,320);

validate();

publicvoid设置日历牌(intyear,intmonth)

日历.set(year,month-1,1);

//Calendar是JAVA默认的类,set(年,月,日)格式,月份是从0开始计为1月,以此类推。

故设置月份参数为month-1

星期几=日历.get(Calendar.DAY_OF_WEEK)-1;

//规定格式,得到此日为星期几

if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)//判断大小月

排列号码(星期几,31);

elseif(month==4||month==6||month==9||month==11)

排列号码(星期几,30);

elseif(month==2)

if((year%4==0&

&

year%100!

=0)||(year%400==0))//判断闰年,平年

排列号码(星期几,29);

else

排列号码(星期几,28);

publicvoid排列号码(int星期几,int月天数)

for(inti=星期几,n=1;

星期几+月天数;

i++)

showDay[i].setText("

+n);

//设置天数,累加

if(n==day)

showDay[i].setForeground(Color.green);

showDay[i].setFont(newFont("

TimesRoman"

Font.BOLD,20));

{

Font.BOLD,12));

showDay[i].setForeground(Color.black);

if(i%7==6)

showDay[i].setForeground(Color.blue);

if(i%7==0)

showDay[i].setForeground(Color.red);

n++;

//程序优化:

显示上个月和下个月部分日期

intlastmonth=month-1;

//取得上个月月份

if(lastmonth==0)

lastmonth=12;

intdate=0;

if(lastmonth==1||lastmonth==3||lastmonth==5||lastmonth==7||lastmonth==8||lastmonth==10||lastmonth==12)

date=31;

elseif(lastmonth==4||lastmonth==6||lastmonth==9||lastmonth==11)

date=30;

elseif(lastmonth==2)

=0)||(year%400==0))

date=29;

date=28;

for(inti=星期几-1;

i>

=0;

i--)//将上个月部分日期放入单元格

showDay[i].setForeground(Color.gray);

showDay[i].setText(date+"

date--;

intflag=1;

//将下个月部分日期放入单元格

for(inti=星期几+月天数;

showDay[i].setText(String.valueOf(flag));

flag++;

publicintgetYear()

returnyear;

publicvoidsetYear(inty)

year=y;

notepad.setYear(year);

publicintgetMonth()

returnmonth;

publicvoidsetMonth(intm)

month=m;

notepad.setMonth(month);

publicintgetDay()

returnday;

publicvoidsetDay(intd)

day=d;

notepad.setDay(day);

publicHashtablegetHashtable()

returnhashtable;

publicFilegetFile()

returnfile;

publicvoidmousePressed(MouseEvente)

JTextFieldsource=(JTextField)e.getSource();

day=Integer.parseInt(source.getText());

notepad.设置信息条(year,month,day);

notepad.设置文本区(null);

notepad.获取日志内容(year,month,day);

catch(Exceptionee)

publicvoidmouseClicked(MouseEvente)

publicvoidmouseReleased(MouseEvente)

publicvoidmouseEntered(MouseEvente)

publicvoidmouseExited(MouseEvente)

publicstaticvoidmain(Stringargs[])

Calendarcalendar=Calendar.getInstance();

inty=calendar.get(Calendar.YEAR);

intm=calendar.get(Calendar.MONTH)+1;

intd=calendar.get(Calendar.DAY_OF_MONTH);

newCalendarPad(y,m,d);

}

YEAR:

importjavax.swing.*;

importjava.awt.*;

importjava.awt.event.*;

publicclassYearextendsBoximplementsActionListener

{

intyear;

intmonth;

JTextFieldshowYear=null;

JButton明年,去年;

CalendarPad日历;

publicYear(CalendarPad日历)

super(BoxLayout.X_AXIS);

showYear=newJTextField(4);

showYear.setBackground(newColor(230,230,250));

showYear.setForeground(newColor(255,20,147));

showYear.setFont(newFont("

TimesRomn"

Font.BOLD,14));

this.日历=日历;

year=日历.getYear();

明年=newJButton("

下年"

明年.setForeground(newColor(0,139,139));

明年.setFont(newFont("

去年=newJButton("

上年"

去年.setFont(newFont("

去年.setForeground(newColor(0,139,139));

add(去年);

add(showYear);

add(明年);

showYear.addActionListener(this);

去年.addActionListener(this);

明年.addActionListener(this);

publicvoidsetYear(intyear)

showYear.setText("

+year);

publicvoidactionPerformed(ActionEvente)

if(e.getSource()==去年)

year=year-1;

日历.setYear(year);

日历.设置日历牌(year,日历.getMonth());

elseif(e.getSource()==明年)

year=year+1;

elseif(e.getSource()==showYear)

try

year=Integer.parseInt(showYear.getText());

catch(NumberFormatExceptionee)

}

第四部分、心得体会

通过这次对日历记事本的程序编写,我对java有了更深一步的探求和理解。

首先是对日历记事本的外观理解、分析,以及查找电脑上、手机上运用的日历记事本的成品,都让我们有了灵感和坚定了决心。

我和隋欣一同完成它经历了许多困难。

因为知识还是有些不足,我们对java许多语句进行了资料的查找和搜集,经过多方面的努力和一遍又一遍地报错

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

当前位置:首页 > 考试认证 > 从业资格考试

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

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