1、 ~第1学期 《Java程序设计》课程 报 告 项目: 日历记事本 专业: 计算机科学和技术 学号: 10570235 姓名: 常兆华 班级: 计算机2班 分数: 角色 姓名 学号 任务分配 小组评定 组长 王思琪 10570226 强制练习工具 组员 常兆华 10570235 日历记事
2、本 隋欣 10570219 日历记事本 杨海钰 10570232 小游戏 关乐 10570231 小游戏 王冕卿 10570223 Atm取款机系统 项 目 说 明 目 录 第一部分、项目整体概述……………………………………………3页 第二部分、我任务…………………………………………………5页 第三部分、代码和具体注释…………………………………………6页 第四部分、心得体会………………………………………………14页 第一部分、项目
3、整体概述 日历记事本----------带有日程提醒功效日历。 2.显示信息: 用户能够看到这个月信息,包含年份、日期等。 点击翻页按钮能够查询前30天日期,也能够向后翻页查询下30天日期。一样,能够依据年份查询不一样年份日期。 日期显示有部分优化,用户不仅能够查询到本月份信息,还能够依据上个月和下个月日期填充来方便查询日期和星期。 3.定时提醒: 用户能够针对某一天来添加、删除和编辑这一天日程提醒信息 当系统时间和提醒时间相吻合时,给出含有
4、提醒信息对话框。 4.查询信息:用户能够查询到某个月全部提醒信息。 日历记事本共有4个java源文件。 CalendarPad.java 该java文件生成类负责创建本日历记事本程序主窗口。该类含有main方法,程序从该类开始实施。 Year.java 该文件负责创建管理年份对象。 Month.java 该文件负责创建管理月份类对象。 NotePad.java 该文件负责创建记事本。 截图: 初始界面 可输入年份查看对应日历和记事本 第二部分、我任务 具体任务: 资料查找,汇总及
5、需求分析,负责日历编写,和板块布局输出等。 编写大致思绪: 我关键负责这个项目中日历编写和输出显示一部分。 经过调查自己电脑中日历记事本和大家纸质日历记事本,我知道若想完整地显示30天信息最少需要一个首先需要一个7*7网格,要用到 GridLayout网格设置语言。其中每一列顶层能够称它为title“标题”,也就是显示“星期几”,表头显示这个月所在年份和月份。随即对日期进行编号,判定闰平年、大小月等必需程序。为了能使用户查找到前十二个月、下十二个月,上一月、下一月内容,还需要设置按钮,让组员变量实现其更改。 总体计划: 主类
6、CanlendarPad 1.组员变量 组员变量描述 变量类型 名称 年、月、日 int year,month,day 保留日志散列表 Hanshtable hanshtable 存放散列表文件 File file 显示日期 JtextFile[] showDay 日历对象 Calendar 日历 记事本对象 NotePad notepad 月 Month 负责改变月 年 Year 负责改变年 2.方法 名称 功效 备注 CalendarPad 创建窗口主程序 结构方法 设置日历牌 设置日立年份、
7、月份 排列号码 排列月份中号码 mousePressed 处理MouseEvent事件 接口方法 main 程序开始运行 第三部分、源代码及具体注释: CalendarPad import java.util.Calendar; //写Calendar类里面导入这个包下全部类库 public class CalendarPad extends JFrame implements MouseListener { //定义CalendarPad类继承JFrame 父类属性 MouseListener鼠标监听 int year,month
8、day;//定义年月日 Hashtable hashtable; //用来保留日志散列哈希表 File file; //存在哈希表中文件 JTextField showDay[]; //天天是7X7一个小格子单元 JLabel title[]; //用来创建日历牌中表格属性“星期几” Calendar 日历;//定义“日历”方法是calendar int 星期几; //整形定义“星期几”方法 NotePad no
9、tepad=null; //日志本对象,初值为空 Month 负责改变月;//定义“负责改变月”方法 Year 负责改变年;//定义“负责改变年”方法 String 星期[]={"星期日","星期一","星期二","星期三","星期四","星期五","星期六"}; JPanel leftPanel,rightPanel; //界面设计,左边是日历,右面为记事本 public CalendarPad(int year,int month,int day)//在CalendarPad类中定义年月日 { ge
10、tContentPane().setBackground(new Color(255, 228, 225));//初始化一个容器,设置颜色值为(255,,228,225) setBackground(new Color(255, 250, 250));//颜色设置 setFont(new Font("微软雅黑", Font.BOLD, 12));//字体设置 setForeground(new Color(70, 130, 180)); setTitle(""); leftPanel=new JPanel();//传入一个布局对象作为参数来
11、创建左边面板 JPanel leftCenter=new JPanel(); JPanel leftNorth=new JPanel(); leftCenter.setLayout(new GridLayout(7,7)); //设置窗口,为7*7网格,参数说明(行数,列数) rightPanel=new JPanel();//设置右侧面板 this.year=year; this.month=month;
12、 this.day=day; 负责改变年=new Year(this); 负责改变年.setFont(new Font("微软雅黑", Font.BOLD, 12));//设置字体 负责改变年.setForeground(new Color(65, 105, 225));//设置前景色 负责改变年.setYear(year);//调用方法 负责改变月=new Month(this); 负责改变月.setFont(new Font("微软雅黑", Font.BOLD, 12));//设置字体 负责改变月.s
13、etForeground(new Color(65, 105, 225));//设置前景色 负责改变月.setMonth(month);//调用方法 title=new JLabel[7];//“星期几”标题,有7个 showDay=new JTextField[42]; //显示日期文件有42个(对应42个网格) for(int j=0;j<7;j++) //标题写入,周日到周一 {
14、 title[j]=new JLabel(); title[j].setText(星期[j]); title[j].setBorder(BorderFactory.createRaisedBevelBorder());//创建边框 leftCenter.add(title[j]); } title[0].setForeground(Color.red);//设置周日为红色 title[6].setForeground(Color.blue);//设置周六为蓝色
15、 for(int i=0;i<42;i++) //日期写入 { showDay[i]=new JTextField(); showDay[i].addMouseListener(this); showDay[i].setEditable(false); leftCenter.add(showDay[i]); } 日历=Calendar.getInstance();//年份月份查询 Box b
16、ox=Box.createHorizontalBox(); box.add(负责改变年); box.add(负责改变月); leftNorth.add(box); leftPanel.setLayout(new BorderLayout()); leftPanel.add(leftNorth,BorderLayout.NORTH);//上方边界 leftPanel.add(leftCenter,BorderLayout.CENTER);//中间 Label label = new Label
17、"请在年份输入框输入所查年份,按回车确定。负数为公元前"); label.setBackground(UIManager.getColor("ScrollBar.foreground"));//具体设置 label.setFont(new Font("黑体", Font.BOLD, 13)); label.setForeground(new Color(204, 0, 0)); leftPanel.add(label, BorderLayout.SOUTH) ;//下方边界 leftPanel.
18、validate(); Container con=getContentPane(); JSplitPane split=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPanel,rightPanel); con.add(split,BorderLayout.CENTER); con.validate(); hashtable=new Hashtable();//初始化哈希表
19、 file=new File("日历记事本.txt");//初始化文件 if(!file.exists()) { try{ FileOutputStream out=new FileOutputStream(file); ObjectOutputStream objectOut=new ObjectOutputStream(out); objectOut.writeObject(hashtable); objectOut.close();
20、 out.close(); } catch(IOException e)//捕捉输入输出异常 { } } notepad=new NotePad(this); //调用notepad数据 rightPanel.add(notepad); 设置日历牌(year,month); addWindowListener(new WindowAdapter
21、) { public void windowClosing(WindowEvent e) { System.exit(0); } }); setVisible(true); setBounds(100,50,612,320); validate(); } public void 设置日历牌(int year,int mo
22、nth) { 日历.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)//判定大小月 { 排列号码(
23、星期几,31); } else if(month==4||month==6||month==9||month==11) { 排列号码(星期几,30); } else if(month==2) { if((year%4==0&&year%100!=0)||(year%400==0)) //判定闰年,平年 { 排列号码(星期几,29); } e
24、lse { 排列号码(星期几,28); } } } public void 排列号码(int 星期几,int 月天数) { for(int i=星期几,n=1;i<星期几+月天数;i++) { showDay[i].setText(""+n);//设置天数,累加 if(n==day) { showDa
25、y[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.b
26、lack); } if(i%7==6) { showDay[i].setForeground(Color.blue); } if(i%7==0) { showDay[i].setForeground(Color.red); } n++;
27、 } //程序优化:显示上个月和下个月部分日期 int lastmonth = month - 1;//取得上个月月份 if(lastmonth == 0) lastmonth = 12; int date = 0; if(lastmonth==1||lastmonth==3||lastmonth==5||lastmonth==7||lastmonth==8||lastmonth==10||lastmonth==12) date = 31
28、 else if(lastmonth==4||lastmonth==6||lastmonth==9||lastmonth==11) date = 30; else if(lastmonth==2) { if((year%4==0&&year%100!=0)||(year%400==0)) date = 29; else date = 28; } for(int i=星期几 - 1;i >= 0;i-
29、)//将上个月部分日期放入单元格 { showDay[i].setForeground(Color.gray); showDay[i].setText(date + ""); date --; } int flag = 1;//将下个月部分日期放入单元格 for(int i=星期几+月天数;i<42;i++) { showDay[i].setFo
30、reground(Color.gray); showDay[i].setText(String.valueOf(flag)); flag ++; } } public int getYear() { return year; } public void setYear(int y) { year=y; notepad.setYear(year); } public int getMonth() {
31、 return month; } public void setMonth(int m) { month=m; notepad.setMonth(month); } public int getDay() { return day; } public void setDay(int d) { day=d; notepad.setDay(day); } public Hashtable getHashtable() { return hasht
32、able; } public File getFile() { return file; } public void mousePressed(MouseEvent e) { JTextField source=(JTextField)e.getSource(); try{ day=Integer.parseInt(source.getText()); notepad.setDay(day); notepad.设置信息条(year,m
33、onth,day); notepad.设置文本区(null); notepad.获取日志内容(year,month,day); } catch(Exception ee) { } } public void mouseClicked(MouseEvent e) { } public void mouseReleased(MouseEvent e) { } public void mouseEntered(MouseEvent e)
34、 { } public void mouseExited(MouseEvent e) { } 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.ge
35、t(Calendar.DAY_OF_MONTH); new CalendarPad(y,m,d); } } YEAR: import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Year extends Box implements ActionListener { int year; int month; JTextFie
36、ld showYear=null; JButton 明年,去年; CalendarPad 日历; public Year(CalendarPad 日历) { super(BoxLayout.X_AXIS); showYear=new JTextField(4); showYear.setBackground(new Color(230, 230, 250)); showYear.setForeground(new Color(255, 20, 147)); showYe
37、ar.setFont(new Font("TimesRomn",Font.BOLD,14)); this.日历=日历; year=日历.getYear(); 明年=new JButton("下年"); 明年.setForeground(new Color(0, 139, 139)); 明年.setFont(new Font("微软雅黑", Font.BOLD, 13)); 去年=new JButton("上年"); 去年.setFont(new Font("微软雅黑", Font.BOLD, 13));
38、 去年.setForeground(new Color(0, 139, 139)); add(去年); add(showYear); add(明年); showYear.addActionListener(this); 去年.addActionListener(this); 明年.addActionListener(this); } public void setYear(int year) { this.year=year; showYear.setText(""+year);
39、 } public int getYear() { return year; } public void actionPerformed(ActionEvent e) { if(e.getSource()==去年) { year=year-1; showYear.setText(""+year); 日历.setYear(year); 日历.设置日历牌(year,日历.getMonth()); } else if(e.getSourc
40、e()==明年) { year=year+1; showYear.setText(""+year); 日历.setYear(year); 日历.设置日历牌(year,日历.getMonth()); } else if(e.getSource()==showYear) { try { year=Integer.parseInt(showYear.getText());
41、showYear.setText(""+year); 日历.setYear(year); 日历.设置日历牌(year,日历.getMonth()); } catch(NumberFormatException ee) { showYear.setText(""+year); 日历.setYear(year); 日历.设置日历牌(year,日历.getMonth());
42、 } } } } 第四部分、心得体会 经过这次对日历记事本程序编写,我对java有了更深一步探求和了解。首先是对日历记事本外观了解、分析,和查找电脑上、手机上利用日历记事本成品,全部让我们有了灵感和坚定了决心。我和隋欣一同完成它经历了很多困难。因为知识还是有些不足,我们对java很多语句进行了资料查找和搜集,经过多方面努力和一遍又一遍地报错排错,最终对于界面设计,我们两个也是很久才达成共识。我们当然也学会了怎样坚持一件事情。使我们很默契配合和精心准备和编写,最终完成了这么一个我们眼中十分完美程序。这是一次极难得体会和经历,这个程序将永远保留在我电脑里当做最宝贵一次课程设计。
©2010-2025 宁波自信网络信息技术有限公司 版权所有
客服电话:4009-655-100 投诉/维权电话:18658249818