个人日程管理软件

个人日程管理软件
个人日程管理软件

课程设计报告

目录

第1部分前言 (3)

第2部分需求分析 (3)

第3部分概要设计 (4)

第4部分详细设计 (4)

第5部分系统测试 (20)

第6部分小结 (23)

第7部分源代码 (23)

一、前言

Java是一个面向对象的程序设计语言,可以让我们更好的掌握面向对象思想解决实际问题的能力。Java拥有庞大的API,其中https://www.360docs.net/doc/0a14005525.html,ng包下的80%的类都是我们必须熟练掌握的,还有其他如:java.awt包,java.io包等等,AWT的基本内容,包括各种组件事件、监听器、布局管理器、常用组件、打印,还有Swing 组件的基本内容等。运用这些强大的API我们可以开发出很多的应用程序。当然,java的优势在网络编程上,但那不等于java在桌面应用程序这一块不可以,java 的思想照样可以做到,甚至更好。

Java是一种纯面向对象的、网络编程首选的语言。Java技术作为软件开的一种革命性技术,已被列为当今世界信息技术的主流之一。为了适应时代潮流,我们应该加强对Java的学习,更好的掌握这门课程。为此,我们成了一个课程小组,经过小组成的商讨之后,我们决定以“日历记事本”为设题材,借此巩固加深我们对Java的了解。

本次课程设计的实例虽然比较简单,程序设计也不是很复杂,但在此程序的设计过程也是一个学习过程,更是对复杂程序的一个学习过程,还能培养我们的数抽象能力。因此,我们觉得这次课程设计是非常有意义的,能为我们今后学习面向过程的程序设计作一些铺垫。

二、需求分析

本系统为日历记事本的设计与实现,主要实现以下功能:

(1)该系统分为两个部分:日历和记事本

(2)该日历可以按年加减,选择年加时,当前日历的年份加一;选择年减时,当前日历年

份减一。

(3)也可以在某年内按月加减。选择月加时,当前日历的月份加一;选择月减时,当前日

历的月份减一。

(4)选择任意某天时,日期也做出相应的变动。

(5)选择日志时,可以实现写日志和读日志的功能。

(6)写日志中可以实现保存,删除,取消,退出的功能。

(7)读日志中可以实现从磁盘中读取日志,退出的功能。

三、概要设计

3.1 系统界面

设计日历记事本系统的主界面,分为两部分:记事本部分和日历部分。具体如图所示:

图为系统界面流程:

3.2 日历部分

日历部分设有三个模块:年份模块,月份模块,日期模块。具体如图所示:

图为日历部分流程:

3.3 记事本部分

记事本部分有两个模块:写模块,读模块;具体如图所示:

图为记事本部分流程:

四、详细设计

4.1 系统界面

系统界面中设置了日历和记事本两个部分,用户可视化界面拖拽主窗口,构造函数的对象添加到面板中。具体如图所示:

图为系统界面流程:

4.2日历部分

日历部分分为三个模块:年模块,月模块,日历模块。年模块中又添加了年加和年减;月模块中也设有月加和月减。日历模块中有日期,星期的排版。

(1)年模块中:根据定义的主函数,添加年加和年减事件,增加相应的监听事件,监听程序执行时,实现年的加减,并且调用响应的函数对日期进行刷新。具体的如图所示:

图为年模块流程:

(2)月模块:根据定义的主函数,添加月加和月减事件,增加相应的监听事件,然后根据响应事件方法实现月的加减。具体如图所示:

图为月模块流程:

(3)记事本

记事本部分分两个模块:写模块和读模块。写模块中添加写日志,写的日志可以保存,删除,取消等;读模块中可以从系统读取日志。

写模块:实现写日志类的监听接口,在构造写日志类中引用类的对象,设计记事本的面板以及处理响应事件,进行获取写日志、保存、删除日志及取消功能的资源,最后进行具体的写日志、保存、删除日志等功能的实现。具体的如图所示:

图为写模块的流程:

读模块:首先实现监听接口构造读取日志类,设计记事本的面板及处理响应事件,然后获取日志的资源,通过具体读取日志功能函数实现对已保存日志进行读取。具体的如图4.3.2所示:

图为读模块的流程:

4.3相应的程序分析

(1)CalendarPad.java的分析

public class CalendarPad extends JFrame implements MouseListener//通过鼠标控制

{ private int year,month,day;

private Hashtable hashTable;

private File file;

private Calendar calendar;

private JPanel leftPanel,rightPanel;

private JTextField showDay[];

private JTextField updo;

private JTextField recordUpdo;

private int dayOfWeek;

private String week[]={"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};

private JLabel title[];

private Year changeYear;

private Month changeMonth;

private NotePad notePad;

public CalendarPad(int year,int month,int day)//建立起界面

{ super("CalendarPad");

Container c=this.getContentPane();

this.year=year;

this.month=month;

this.day=day;

changeYear=new Year(this);

changeMonth=new Month(this);

changeYear.setYear(year);

changeMonth.setMonth(month);

calendar=Calendar.getInstance();

leftPanel=new JPanel();

rightPanel=new JPanel();

JPanel leftNorthPanel=new JPanel();

Box box=Box.createHorizontalBox();

box.add(changeYear);

box.add(changeMonth);

leftNorthPanel.add(box);

JPanel leftCenterPanel=new JPanel();

leftCenterPanel.setLayout(new GridLayout(7,7));

title=new JLabel[7];

for(int i=0;i<7;i++)

{ title[i]=new JLabel(week[i]);

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

leftCenterPanel.add(title[i]);}

title[0].setForeground(Color.magenta);//周末日期为紫色

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

showDay=new JTextField[42];

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

{ showDay[i]=new JTextField();

leftCenterPanel.add(showDay[i]);

showDay[i].addMouseListener(this);

showDay[i].setEditable(false);}

leftPanel.setLayout(new BorderLayout());

leftPanel.add(leftNorthPanel,BorderLayout.NORTH);

leftPanel.add(leftCenterPanel,BorderLayout.CENTER);

leftPanel.validate();

JSplitPanejSplit=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,leftPa nel,rightPanel);

c.add(jSplit);

c.validate();

hashTable=new Hashtable(); //所记录下的存文件,取名Diary

file=new File("Diary.txt");

if(!file.exists())

{try

{FileOutputStream out=new FileOutputStream(file);

ObjectOutputStream objectOut=new ObjectOutputStream(out);

objectOut.writeObject(hashTable);

objectOut.close();

out.close();}catch(IOException e){}}

notePad=new NotePad(this);

rightPanel.add(notePad);

this.setCalendarPad(this.year, this.month);

this.addWindowListener(new WindowAdapter()

{ public void windowClosing(WindowEvent e)

{System.exit(0);}});

this.setBounds(200, 200, 560, 300);

this.setResizable(false);

this.setVisible(true);

this.validate();

recordUpdo=new JTextField();}

public int getDay() {return day;}

public void setDay(int day) {this.day = day;}

public int getMonth() {return month;}

public void setMonth(int month) {this.month = month;}

public Hashtable getHashtable() {return hashTable;}

public void setYear(int year)

{this.year=year;

changeYear.setYear(year);

notePad.setYear(year);}

public int getYear()

{return this.year;}

public void setCalendarPad(int year,int month)

{

calendar.set(year, month-1, 1);

dayOfWeek=calendar.get(Calendar.DAY_OF_WEEK)-1;

switch(month)

{ case 2:

if((year%100!=0&&year%4==0)||year%400==0) //考虑是否闰年的问题

orderDay(dayOfWeek,29,year,month);

else

orderDay(dayOfWeek,28,year,month);

break;

case 4:

case 6:

case 9:

case 11:

orderDay(dayOfWeek,30,year,month);

break;

default:

orderDay(dayOfWeek,31,year,month);

break;}

}

public void orderDay(int dayOfweek,int daysOfMonth,int year,int month)//鼠标点击控制日期的颜色变化

{for(int i=0;i

{showDay[i].setText("");

showDay[i].removeMouseListener(this);

showDay[i].setBackground(new Color(238,238,238));} for(int i=dayOfweek,n=1;i

{showDay[i].setText(""+n);

showDay[i].setBackground(new Color(238,238,238));

showDay[i].addMouseListener(this);

NotePad nPad=new NotePad(this);

nPad.setDay(n);

nPad.setMessage(year, month, n);

if(nPad.haveNote(year, month, n)){

this.setTop(showDay[i], year, month, n);

}else {

showDay[i].setBackground(new Color(238,238,238));

}

if(n==day)

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

showDay[i].setFont(new Font("TimesRoman",Font.BOLD,20)); }

else

{ showDay[i].setFont(new Font("TimesRoman",Font.BOLD,12));

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

}

if(i%7==6)

showDay[i].setForeground(Color.magenta);//周六或周日的区域颜色为红色

if(i%7==0)

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

n++;

}

for(int i=dayOfweek+daysOfMonth;i<42;i++)

{

showDay[i].setText("");

showDay[i].removeMouseListener(this);

}}

public File getFile()

{return file;}

public void mouseClicked(MouseEvent e) {}

public void mouseEntered(MouseEvent e) {}

public void mouseExited(MouseEvent e) {}

public void mouseReleased(MouseEvent e) {}

public void mousePressed(MouseEvent e)

{JTextField source=(JTextField)e.getSource();

if(!source.getForeground().equals(Color.red)){

if(updo!=null){//恢复上一个日期的格式

updo.setForeground(recordUpdo.getForeground());

updo.setFont(new

Font("TimesRoman",Font.BOLD,recordUpdo.getFont().getSize()));}//采集当前的日期格式

updo=source;

recordUpdo.setForeground(updo.getForeground());

recordUpdo.setFont(new

Font("TimesRoman",Font.BOLD,updo.getFont().getSize()));

recordUpdo.setText(updo.getText());//突出显示选中的日期

source.setForeground(Color.red);

source.setFont(new Font("TimesRoman",Font.BOLD,20));} day=Integer.parseInt(source.getText());

notePad.setDay(day);

notePad.setMessage(year, month, day);

if(notePad.haveNote(year, month, day)){

this.setTop(source, year, month, day);}

else {source.setBackground(new Color(238,238,238));

}

notePad.getContent(year, month, day);

}

public void setTop(JTextField source,int year,int month ,int day){ Calendar calendar=Calendar.getInstance();

int y=calendar.get(Calendar.YEAR);

int m=calendar.get(Calendar.MONTH)+1;

int d=calendar.get(Calendar.DAY_OF_MONTH);

if(https://www.360docs.net/doc/0a14005525.html,pareDate(y, m, d, year, month, day)==1){

source.setBackground(Color.cyan);//如果上下月的当月日期与上点击的匹配,颜色变成蓝绿色

}else if(https://www.360docs.net/doc/0a14005525.html,pareDate(y, m, d, year, month, day)==3){ source.setBackground(Color.yellow);//如有记事,则该日期颜色变黄

}else {

source.setBackground(Color.orange);//否则就都是橘黄色}

}

public int compareDate(int y,int m ,int d,int year,int month,int day){ if(y>year){return 1;

}else if(y

}else if(m>month){return 1;

}else if(m

}else if (d>day) {return 1;

}else if (day

}else {return 2;}

}

public static void main(String args[]) //主方法

{

Calendar calendar=Calendar.getInstance();

int y=calendar.get(Calendar.YEAR);

int m=calendar.get(Calendar.MONTH)+1;

int d=calendar.get(Calendar.DAY_OF_MONTH);

new CalendarPad(y,m,d); }}

(2)Month.java的分析

class Month extends Box implements ActionListener //记录月份的方法{private static final long serialVersionUID = 1L;

private int month;

private CalendarPad calendarPad;

private JTextField showMonth;

private JButton preMonth,nextMonth;

public Month(CalendarPad calendar)

{ super(BoxLayout.X_AXIS);

calendarPad= calendar;

showMonth=new JTextField(4);

showMonth.setForeground(Color.BLUE);

showMonth.setFont(new Font("TimesRomn",Font.BOLD,15));

showMonth.setEnabled(false);

month=calendar.getMonth();

preMonth=new JButton("上月");

nextMonth=new JButton("下月");

this.add(preMonth);

this.add(showMonth);

this.add(nextMonth);

preMonth.addActionListener(this);

nextMonth.addActionListener(this);

}

public int getMonth() {return month;}

public void setMonth(int month)

{if(month<=12||month>=1)

{this.month = month;}

else

this.month=1;

showMonth.setText(""+month);}

public void actionPerformed(ActionEvent e)

{if(e.getSource()==preMonth)

{if(month>1){

this.month=this.month-1;

calendarPad.setYear(calendarPad.getYear());

calendarPad.setCalendarPad(calendarPad.getYear(),this.month);

}else

{this.month=12;

calendarPad.setYear(calendarPad.getYear()-1);

calendarPad.setCalendarPad(calendarPad.getYear()-1,this.month);} showMonth.setText(""+month);

calendarPad.setMonth(month);}

if(e.getSource()==nextMonth)

{if(month>0&&month<12)

{this.month=this.month+1;

calendarPad.setYear(calendarPad.getYear());

calendarPad.setCalendarPad(calendarPad.getYear(),this.month);} else{this.month=1;

calendarPad.setYear(calendarPad.getYear()+1);

calendarPad.setCalendarPad(calendarPad.getYear()+1,this.month);} showMonth.setText(""+month);

calendarPad.setMonth(month); }}}

(3)NotePad.java的分析

class NotePad extends JPanel implements ActionListener //需要添加事情的方法

{private int year,month,day;

private JLabel message;

private JButton save,delete;

private JTextArea area;

private Hashtable hashTable;

private File file;

private CalendarPad calendarPad;

public NotePad(CalendarPad calendar)

{calendarPad=calendar;

file=calendarPad.getFile();

year=calendarPad.getYear();

month=calendarPad.getMonth();

day=calendarPad.getDay();

hashTable=new Hashtable();

message=new JLabel(year+"年"+month+"月"+day+"日");

message.setFont(new Font("新宋体",Font.BOLD,24));

message.setForeground(Color.BLUE);

area=new JTextArea(10,15);

save=new JButton("Add");

delete=new JButton("Delete");

save.addActionListener(this);

delete.addActionListener(this);

JPanel south=new JPanel();

south.add(save);

south.add(delete);

this.setLayout(new BorderLayout());

this.add(south,BorderLayout.SOUTH);

this.add(new JScrollPane(area),BorderLayout.CENTER);

this.add(message,BorderLayout.NORTH);}

public void actionPerformed(ActionEvent e)

{if(e.getSource()==save)

{save(year,month,day);}

if(e.getSource()==delete)

{delete(year,month,day);}}

public int getDay() {

return day;}

public void setDay(int day) {

this.day = day;}

public int getMonth() {

return month;}

public void setMonth(int month) {

this.month = month; }

public int getYear() {

return year;}

public void setYear(int year) {

this.year = year;}

public void setMessage(int year,int month,int day)

{message.setText(year+"年"+month+"月"+day+"日");}

public void getContent(int year,int month,int day)//获取自己输入内容的方法

{String key=year+"年"+month+"月"+day+"日";

try { FileInputStream input = new FileInputStream(file);

ObjectInputStream objectinput=new

ObjectInputStream(input);

hashTable=(Hashtable)objectinput.readObject();

objectinput.close();

input.close();

} catch (FileNotFoundException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

} catch (ClassNotFoundException e) {

e.printStackTrace();}

if(hashTable.containsKey(key))

{area.setText((String)hashTable.get(key));

}else

area.setText("No record!");}

public boolean haveNote(int year,int month,int day) //判断是否有安排记事

{String key=year+"年"+month+"月"+day+"日";

try {FileInputStream input = new FileInputStream(file);

ObjectInputStream objectinput=new

ObjectInputStream(input);

hashTable=(Hashtable)objectinput.readObject();

objectinput.close();

input.close();

} catch (FileNotFoundException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

} catch (ClassNotFoundException e) {

e.printStackTrace();

}

if(hashTable.containsKey(key))

{return true;

}else {return false ;} }

public void setContent(String s)

{area.setText(s);}

public void save(int year,int month,int day)

{ String content=area.getText();

String key=year+"年"+month+"月"+day+"日";

String m=year+"年"+month+"月"+day+"日"+" Save?";

int ok=JOptionPane.showConfirmDialog(this, m, "ask", JOptionPane.YES_NO_OPTION,

JOptionPane.QUESTION_MESSAGE);

if(ok==JOptionPane.YES_OPTION)

{

try {

FileInputStream input = new FileInputStream(file);

ObjectInputStream objectinput=new

ObjectInputStream(input);

hashTable=(Hashtable)objectinput.readObject();

objectinput.close();

input.close();

hashTable.put(key, content);

FileOutputStream output = new FileOutputStream(file);

ObjectOutputStream objectoutput=new

ObjectOutputStream(output);

objectoutput.writeObject(hashTable);

objectoutput.close();

output.close();

} catch (FileNotFoundException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

} catch (ClassNotFoundException e) {

e.printStackTrace();

}

}

}

public void delete(int year,int month,int day)//删除的方法

{

String key=year+"年"+month+"月"+day+"日";

if(hashTable.containsKey(key))

{

String m=year+"年"+month+"月"+day+"日"+" Delete?";

int ok=JOptionPane.showConfirmDialog(this, m, "ask", JOptionPane.YES_NO_OPTION,

JOptionPane.QUESTION_MESSAGE);

if(ok==JOptionPane.YES_OPTION)

{

try {

FileInputStream input = new FileInputStream(file);

ObjectInputStream objectinput=new

ObjectInputStream(input);

hashTable=(Hashtable)objectinput.readObject();

objectinput.close();

input.close();

hashTable.remove(key);

FileOutputStream output = new FileOutputStream(file);

ObjectOutputStream objectoutput=new

ObjectOutputStream(output);

objectoutput.writeObject(hashTable);

objectoutput.close();

output.close();

} catch (FileNotFoundException e) {

e.printStackTrace();}

catch (IOException e) {

e.printStackTrace();

} catch (ClassNotFoundException e) {

e.printStackTrace();

}

area.setText("");}

}else

{

String warn="There is no record today!";

JOptionPane.showMessageDialog(this, warn,"Warning",JOptionPane.WARNING_MESSAGE);} }}

(4)Year.java的分析

class Year extends Box implements ActionListener

{ private static final long serialVersionUID = 1L;

int year;

JTextField showYear;

JButton preYear,nextYear;

CalendarPad calendarPad;

public Year(CalendarPad calendar)

{ super(BoxLayout.X_AXIS);

showYear=new JTextField(4);

showYear.setForeground(Color.BLUE);

showYear.setFont(new Font("TimesRomn",Font.BOLD,15));

showYear.setEnabled(false);

preYear=new JButton("上年");

nextYear=new JButton("下年");

this.calendarPad=calendar;

year=calendarPad.getYear();

this.add(preYear);

this.add(showYear);

this.add(nextYear);

preYear.addActionListener(this);

nextYear.addActionListener(this);}

public void setYear(int year)

{ this.year=year;

showYear.setText(""+year);}

public int getYear()

{return this.year;}

public void actionPerformed(ActionEvent e)

{if(e.getSource()==preYear)

{ this.year=this.year-1;

showYear.setText(""+year);

calendarPad.setYear(year);

calendarPad.setCalendarPad(year,calendarPad.getMonth());} if(e.getSource()==nextYear)

{ this.year=this.year+1;

showYear.setText(""+year);

calendarPad.setYear(year);

calendarPad.setCalendarPad(year,calendarPad.getMonth());}}

五、系统测试

系统中设有主类CalendarPad,类中加有菜单和面板,菜单中设有年份,月份,日志。日期,星期等都添加到面板中。整个程序运行以后出现如图的界面。

图为系统效果图:

修改年份.,单击菜单项目中的年加或年减时,日期中的年份随之改变,并且日历也跟着变动。整个程序运行以后出现如图的界面:

图为年份修改后窗口效果:

相关主题
相关文档
最新文档