java课程设计任务书Word文档下载推荐.docx
- 文档编号:14896022
- 上传时间:2022-10-25
- 格式:DOCX
- 页数:77
- 大小:327.50KB
java课程设计任务书Word文档下载推荐.docx
《java课程设计任务书Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《java课程设计任务书Word文档下载推荐.docx(77页珍藏版)》请在冰豆网上搜索。
Month.java
该文件负责创建管理月份的对象。
NotePad.java
该文件负责创建记事本。
4.具体设计
4.1主类CalendarPad
1.成员变量(见下表)
主要成员变量(属性)
成员变量描述
变量类型
名称
年、月、日
int
year,month,day
保存日志的散列表
Hashtable
hashtable
存放散列表的文件
File
file
显示日期
JTextField[]
showDay
日历对象
Calendar
日历
记事本对象
NotePad
notepad
月
Month
负责改变年
年
Year
负责改变月
2.方法(见下表)
主要方法
功能
备注
CalendarPad
创建程序主窗口
构造方法
设置日历牌
设置日历的年份、月份
排列号码
排列月份中的号码
mousePressed
处理MouseEvent事件
接口方法
main
程序开始运行
3.代码
importjava.util.Calendar;
importjavax.swing.*;
importjava.awt.*;
importjava.awt.event.*;
importjava.io.*;
importjava.util.Hashtable;
publicclassCalendarPadextendsJFrameimplementsMouseListener
{
intyear,month,day;
Hashtablehashtable;
//用来保存日志的散列表
Filefile;
//保存散列表的文件
JTextFieldshowDay[];
//显示日期的文本条数组
JLabeltitle[];
//日历牌的星期标题
Calendar日历;
int星期几;
NotePadnotepad=null;
//记事本对象
Month负责改变月;
Year负责改变年;
String星期[]={"
星期日"
"
星期一"
星期二"
星期三"
星期四"
星期五"
星期六"
};
JPanelleftPanel,rightPanel;
publicCalendarPad(intyear,intmonth,intday)
{
leftPanel=newJPanel();
JPanelleftCenter=newJPanel();
JPanelleftNorth=newJPanel();
leftCenter.setLayout(newGridLayout(7,7));
//第一行显示星期标题的标签
//后续6行显示日期的标签
rightPanel=newJPanel();
this.year=year;
this.month=month;
this.day=day;
负责改变年=newYear(this);
负责改变年.setYear(year);
负责改变月=newMonth(this);
负责改变月.setMonth(month);
title=newJLabel[7];
//负责显示星期标题的标签
showDay=newJTextField[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容//器,从左向右显示年份、月份
box.add(负责改变年);
box.add(负责改变月);
leftNorth.add(box);
leftPanel.setLayout(newBorderLayout());
leftPanel.add(leftNorth,BorderLayout.NORTH);
leftPanel.add(leftCenter,BorderLayout.CENTER);
leftPanel.add(newLabel("
请在年份输入框输入所查年份(负数表示公元前),并回车确定"
),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);
//创建记事本对象
rightPanel.add(notepad);
设置日历牌(year,month);
addWindowListener(newWindowAdapter()
{publicvoidwindowClosing(WindowEvente)
System.exit(0);
});
setVisible(true);
setBounds(100,50,524,285);
validate();
publicvoid设置日历牌(intyear,intmonth)
日历.set(year,month-1,1);
星期几=日历.get(Calendar.DAY_OF_WEEK)-1;
if(month==1||month==2||month==3||month==5||month==7//从当月1日开始依次
||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++;
星期几;
for(inti=星期几+月天数;
publicintgetYear()
returnyear;
publicvoidsetYear(inty)
year=y;
notepad.setYear(year);
publicintgetMonth()
returnmonth;
publicvoidsetMonth(intm)
month=m;
notepad.setMonth(month);
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- java 课程设计 任务书