java设计报告.docx

上传人:b****0 文档编号:9493358 上传时间:2023-05-19 格式:DOCX 页数:28 大小:335.73KB
下载 相关 举报
java设计报告.docx_第1页
第1页 / 共28页
java设计报告.docx_第2页
第2页 / 共28页
java设计报告.docx_第3页
第3页 / 共28页
java设计报告.docx_第4页
第4页 / 共28页
java设计报告.docx_第5页
第5页 / 共28页
java设计报告.docx_第6页
第6页 / 共28页
java设计报告.docx_第7页
第7页 / 共28页
java设计报告.docx_第8页
第8页 / 共28页
java设计报告.docx_第9页
第9页 / 共28页
java设计报告.docx_第10页
第10页 / 共28页
java设计报告.docx_第11页
第11页 / 共28页
java设计报告.docx_第12页
第12页 / 共28页
java设计报告.docx_第13页
第13页 / 共28页
java设计报告.docx_第14页
第14页 / 共28页
java设计报告.docx_第15页
第15页 / 共28页
java设计报告.docx_第16页
第16页 / 共28页
java设计报告.docx_第17页
第17页 / 共28页
java设计报告.docx_第18页
第18页 / 共28页
java设计报告.docx_第19页
第19页 / 共28页
java设计报告.docx_第20页
第20页 / 共28页
亲,该文档总共28页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

java设计报告.docx

《java设计报告.docx》由会员分享,可在线阅读,更多相关《java设计报告.docx(28页珍藏版)》请在冰点文库上搜索。

java设计报告.docx

java设计报告

Java课程设计报告

 

 

题目:

日历记事本

班级:

12信算2 

姓名/学号:

曹雄港(1200801221)

刘磊(1200801234)

指导教师:

杨静华 

完成时间:

2013年6月23日

1.题目内容:

日历记事本

2.设计分析:

要求:

带有日程提醒功能的日历。

(1)显示信息:

用户可以向前翻页查询前一个月的日期,也可以向后翻页查询下一个月的日期。

(2)定时提醒:

用户可以针对某一天来添加,删除和编辑这一天的日程提醒信息,当系统时间和提醒时间相吻合时,给出具有提示信息的对话框。

(3)查询信息:

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

3.源程序:

主程序:

CalendarPad.java

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));

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.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

||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++;

}

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

{

showDay[i].setText("");

}

for(inti=星期几+月天数;i<42;i++)

{

showDay[i].setText("");

}

}

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);

}

}

辅助类1:

Year.java(自编名词,不知道叫什么。

见谅见谅。

importjavax.swing.*;

importjava.awt.*;

importjava.awt.event.*;

publicclassYearextendsBoximplementsActionListener

{

intyear;

intmonth;

JTextFieldshowYear=null;

JButton明年,去年;

CalendarPad日历;

publicYear(CalendarPad日历)

{

super(BoxLayout.X_AXIS);

showYear=newJTextField(4);

showYear.setForeground(Color.blue);

showYear.setFont(newFont("TimesRomn",Font.BOLD,14));

this.日历=日历;

year=日历.getYear();

明年=newJButton("下年");

去年=newJButton("上年");

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());

}

}

}

}

辅助类2:

month.java

importjavax.swing.*;

importjava.awt.*;

importjava.awt.event.*;

publicclassMonthextendsBoximplementsActionListener

{

intmonth;

JTextFieldshowMonth=null;

JButton下月,上月;

CalendarPad日历;

publicMonth(CalendarPad日历)

{

super(BoxLayout.X_AXIS);

this.日历=日历;

showMonth=newJTextField

(2);

month=日历.getMonth();

showMonth.setEditable(false);

showMonth.setForeground(Color.blue);

showMonth.setFont(newFont("TimesRomn",Font.BOLD,16));

下月=newJButton("下月");

上月=newJButton("上月");

add(上月);

add(showMonth);

add(下月);

上月.addActionListener(this);

下月.addActionListener(this);

showMonth.setText(""+month);

}

publicvoidsetMonth(intmonth)

{

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

{

this.month=month;

}

else

{

this.month=1;

}

showMonth.setText(""+month);

}

publicintgetMonth()

{

returnmonth;

}

publicvoidactionPerformed(ActionEvente)

{

if(e.getSource()==上月)

{

if(month>=2)

{

month=month-1;

日历.setMonth(month);

日历.设置日历牌(日历.getYear(),month);

}

elseif(month==1)

{

month=12;

日历.setMonth(month);

日历.设置日历牌(日历.getYear(),month);

}

showMonth.setText(""+month);

}

elseif(e.getSource()==下月)

{

if(month<12)

{

month=month+1;

日历.setMonth(month);

日历.设置日历牌(日历.getYear(),month);

}

elseif(month==12)

{

month=1;

日历.setMonth(month);

日历.设置日历牌(日历.getYear(),month);

}

showMonth.setText(""+month);

}

}

 

}

辅助类3:

NotePad.java

importjava.awt.*;

importjava.awt.event.*;

importjava.util.*;

importjavax.swing.*;

importjavax.swing.event.*;

importjava.io.*;

publicclassNotePadextendsJPanelimplementsActionListener

{

JTextAreatext;

JButton保存日志,删除日志;

Hashtabletable;

JLabel信息条;

intyear,month,day;

Filefile;

CalendarPadcalendar;

publicNotePad(CalendarPadcalendar)

{

this.calendar=calendar;

year=calendar.getYear();

month=calendar.getMonth();

day=calendar.getDay();;

table=calendar.getHashtable();

file=calendar.getFile();

信息条=newJLabel(""+year+"年"+month+"月"+day+"日",JLabel.CENTER);

信息条.setFont(newFont("TimesRoman",Font.BOLD,16));

信息条.setForeground(Color.blue);

text=newJTextArea(10,10);

保存日志=newJButton("保存日志");

删除日志=newJButton("删除日志");

保存日志.addActionListener(this);

删除日志.addActionListener(this);

setLayout(newBorderLayout());

JPanelpSouth=newJPanel();

add(信息条,BorderLayout.NORTH);

pSouth.add(保存日志);

pSouth.add(删除日志);

add(pSouth,BorderLayout.SOUTH);

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

}

publicvoidactionPerformed(ActionEvente)

{

if(e.getSource()==保存日志)

{

保存日志(year,month,day);

}

elseif(e.getSource()==删除日志)

{

删除日志(year,month,day);

}

}

publicvoidsetYear(intyear)

{

this.year=year;

}

publicintgetYear()

{

returnyear;

}

publicvoidsetMonth(intmonth)

{

this.month=month;

}

publicintgetMonth()

{

returnmonth;

}

publicvoidsetDay(intday)

{

this.day=day;

}

publicintgetDay()

{

returnday;

}

publicvoid设置信息条(intyear,intmonth,intday)

{

信息条.setText(""+year+"年"+month+"月"+day+"日");

}

publicvoid设置文本区(Strings)

{

text.setText(s);

}

publicvoid获取日志内容(intyear,intmonth,intday)

{

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

try

{

FileInputStreaminOne=newFileInputStream(file);

ObjectInputStreaminTwo=newObjectInputStream(inOne);

table=(Hashtable)inTwo.readObject();

inOne.close();

inTwo.close();

}

catch(Exceptionee)

{

}

if(table.containsKey(key))

{

St

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

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

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2