新记事本java程序设计报告.docx
- 文档编号:10340031
- 上传时间:2023-05-25
- 格式:DOCX
- 页数:19
- 大小:139.27KB
新记事本java程序设计报告.docx
《新记事本java程序设计报告.docx》由会员分享,可在线阅读,更多相关《新记事本java程序设计报告.docx(19页珍藏版)》请在冰点文库上搜索。
新记事本java程序设计报告
2012~2013学年度第1学期
《Java程序设计》课程
报告
项目:
日历记事本
专业:
计算机科学与技术
学号:
10570235
姓名:
常兆华
班级:
计算机2班
分数:
角色
姓名
学号
任务分配
小组评定
组长
王思琪
10570226
强制练习工具
组员
常兆华
10570235
日历记事本
隋欣
10570219
日历记事本
杨海钰
10570232
小游戏
关乐
10570231
小游戏
王冕卿
10570223
Atm取款机系统
项目说明
第一部分、项目整体概述……………………………………………3页
第二部分、我的任务…………………………………………………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("微软雅黑",Font.BOLD,12));//设置字体
负责改变年.setForeground(newColor(65,105,225));//设置前景色
负责改变年.setYear(year);//调用方法
负责改变月=newMonth(this);
负责改变月.setFont(newFont("微软雅黑",Font.BOLD,12));//设置字体
负责改变月.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<星期几+月天数;i++)
{
showDay[i].setText(""+n);//设置天数,累加
if(n==day)
{
showDay[i].setForeground(Color.green);
showDay[i].setFont(newFont("TimesRoman",Font.BOLD,20));
}
else
{
showDay[i].setFont(newFont("TimesRoman",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)
{
if((year%4==0&&year%100!
=0)||(year%400==0))
date=29;
else
date=28;
}
for(inti=星期几-1;i>=0;i--)//将上个月部分日期放入单元格
{
showDay[i].setForeground(Color.gray);
showDay[i].setText(date+"");
date--;
}
intflag=1;//将下个月部分日期放入单元格
for(inti=星期几+月天数;i<42;i++)
{
showDay[i].setForeground(Color.gray);
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();
try{
day=Integer.parseInt(source.getText());
notepad.setDay(day);
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("微软雅黑",Font.BOLD,13));
去年=newJButton("上年");
去年.setFont(newFont("微软雅黑",Font.BOLD,13));
去年.setForeground(newColor(0,139,139));
add(去年);
add(showYear);
add(明年);
showYear.addActionListener(this);
去年.addActionListener(this);
明年.addActionListener(this);
}
publicvoidsetYear(intyear)
{
this.year=year;
showYear.setText(""+year);
}
publicintgetYear()
{
returnyear;
}
publicvoidactionPerformed(ActionEvente)
{
if(e.getSource()==去年)
{
year=year-1;
showYear.setText(""+year);
日历.setYear(year);
日历.设置日历牌(year,日历.getMonth());
}
elseif(e.getSource()==明年)
{
year=year+1;
showYear.setText(""+year);
日历.setYear(year);
日历.设置日历牌(year,日历.getMonth());
}
elseif(e.getSource()==showYear)
{
try
{
year=Integer.parseInt(showYear.getText());
showYear.setText(""+year);
日历.setYear(year);
日历.设置日历牌(year,日历.getMonth());
}
catch(NumberFormatExceptionee)
{
showYear.setText(""+year);
日历.setYear(year);
日历.设置日历牌(year,日历.getMonth());
}
}
}
}
第四部分、心得体会
通过这次对日历记事本的程序编写,我对java有了更深一步的探求和理解。
首先是对日历记事本的外观理解、分析,以及查找电脑上、手机上运用的日历记事本的成品,都让我们有了灵感和坚定了决心。
我和隋欣一同完成它经历了许多困难。
因为知识还是有些不足,我们对java许多语句进行了资料的查找和搜集,经过多方面的努力和一遍又一遍地报错排错,最
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 记事本 java 程序设计 报告