收藏 分销(赏)

java专业课程设计万年历程序设计方案报告.doc

上传人:精**** 文档编号:2658700 上传时间:2024-06-03 格式:DOC 页数:34 大小:237.54KB
下载 相关 举报
java专业课程设计万年历程序设计方案报告.doc_第1页
第1页 / 共34页
java专业课程设计万年历程序设计方案报告.doc_第2页
第2页 / 共34页
java专业课程设计万年历程序设计方案报告.doc_第3页
第3页 / 共34页
java专业课程设计万年历程序设计方案报告.doc_第4页
第4页 / 共34页
java专业课程设计万年历程序设计方案报告.doc_第5页
第5页 / 共34页
点击查看更多>>
资源描述

1、山东科技大学信息学院JAVA程序设计 学 院 :信息科学和工程学院 班 级 :计算机 11-3 学 号 :01050230 姓 名 : 赵乐 目 录目 录1序言11需求分析22.概要设计33.各模块功效及程序说明54测试分析135源程序清单136课程设计体会22序言Java前身是Oak,它一开始只是被应用于消费性电子产品中。以后它开发者们发觉它还能够被用于更大范围Internet上。1995年,Java语言名字从Oak编程了Java。1997年J2SE1.1公布。1998年J2SE1.2公布,标志Java2诞生。十多年来,Java编程语言及平台成功地利用在网络计算及移动等各个领域。Java体系

2、结构由Java语言、Java class、Java API、Java虚拟机组成。它含有简单、面向对象、健壮、安全、结构中立、可移植和高效能等众多优点。Java支持多线程编程,Java运行时系统在多线程同时方面含有成熟处理方案。Java平台标准有Java ME,Java SE和Java EE。Java发展到今天,它卓越成就及在业界地位毋庸置疑。现在在众多支持Java开发工具中关键7有Java Development Kit,NetBeans,Jcreator,JBuilder,JDeveloper和Eclipse等。其中Java Development Kit 简称JDK是大多开发工具基础。以上

3、每种开发工具全部有优缺点,对于开发者来说,关键是要依据自己开发规模、开发内容和软硬件环境等原因来选择一个适宜开发工具。1需求分析1.1需求分析本程序要求为:1.使用图形用户界面;2.本程序能够实现日期和星期查询。1.2功效设计本程序要构建万年历程序,其功效有以下多个方面:(1)经过网页形式运行,实现图形界面。(2)能以月历形式显示日期和星期。 (3)支持用户自己输入年份,并提供月份下拉形式菜单来选择月份。 (4)经过点击“更新”来刷新日历。2.概要设计2.1程序设计思绪1. 总天数算法:首先用if语句判定定义年到输入年之间每十二个月是否为闰年,是闰年,该年总天数为366,不然,为365。然后判

4、定输入年是否为定义年,若是,令总天数S=1,不然,用累加法计算出定义年到输入年之间总天数,再把输入年一月到要输出月份之间天数累加起来,若该月是闰年中月份而且该月还大于二月,再使总天数加1,不然,不加,既算出从定义年一月一日到输出年该月一日总天数。2. 输出月份第一天为星期几算法:使总天数除以7取余加2得几既为星期几,若是7,则为星期日。3. 算出输出月份第一天为星期几算法:算出输出月份第一天为星期几后,把该日期以前位置用空格补上,并总该日起一次输出天数直到月底,该月中天数加上该月一日为星期几数字再除以7得0换行,即可完整输出该月日历。4. 假如年份小于1582年则程序不予判定。2.2程序运行界

5、面图2-1 程序运行界面2.3步骤图开始初始化程序,获取目前日期调取目前日期下日志文件绘制界面判定日期是否更新结束3.各模块功效及程序说明3.1.初始化组件import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.MouseEvent;import java.awt.event.MouseListener;import java.io.BufferedReader;import java.io.BufferedWriter;impo

6、rt java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStreamReader;import java.io.OutputStreamWriter;/import java.sql.Date;import java.text.DateFormat;import java.text.SimpleDateFormat;import

7、 java.util.Calendar;import java.util.Date;import javax.swing.JButton;import javax.swing.JDialog;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.JTable;import javax.swing.JTextArea;import ja

8、vax.swing.JTextField;import javax.swing.table.DefaultTableModel;3.2.初始化数据private Calendar cld = Calendar.getInstance();private String astr = 星期一, 星期二, 星期三, 星期四, 星期五, 星期六, 星期日;private DefaultTableModel dtm = new DefaultTableModel(null,astr);private JTable table = new JTable(dtm); /装日期表格private JScrol

9、lPane sp = new JScrollPane(table);private JButton bLastYear = new JButton(上十二个月);private JButton bNextYear = new JButton(下十二个月);private JButbNextMonth = new JButton(下月);private JTextField jtfYear = new JTextField(5);/jtfYear年份显示和输入文本框private JTextField jtfMonth = new JTextField(2);/jtfMonth月份显示文本框pr

10、ivate JPanel p1 = new JPanel(); /装入控制日期按钮模块private JPanel p2 = new JPanel();private JPanel p3 = new JPanel(new BorderLayout();private JPanel p4 = new JPanel(new GridLayout(2,1);private JPanel p5 = new JPanel(new BorderLayout();private JButton bAdd = new JButton(保留日志);private JButton bDel = new JButt

11、on(删除日志);private JTextArea jta = new JTextArea(); /jta-JTextAreaprivate JScrollPane jsp = new JScrollPane(jta);private JLabel l = new JLabel(年份文本框中可直接键入要查找年份,以提升查询效率);private JLabel lt = new JLabel();private JLabel ld = new JLabel();private int lastTime;3.3.绘制程序界面 public wannianli() super(万年历); /框架命

12、名 this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);/窗口关闭函数 this.getContentPane().setLayout(new BorderLayout(10, 0); jta.setLineWrap(true); table.setGridColor(Color.GRAY); /星期之间网格线是灰色 table.setColumnSelectionAllowed(true); table.setSelectionBackground(Color.BLACK);/当选定某一天时这一天背景黑色 table.setSelectio

13、nForeground(Color.GREEN);/选定日期字体是绿色 table.setBackground(new Color(184,207,229);/日期显示表格颜色浅蓝色 table.setFont(new Font(黑体,Font.BOLD,24);/日期数字字体格式 table.setRowHeight(30);/表格高度 table.addMouseListener(this); /鼠标监听器 jtfYear.addActionListener(this);/可输入年份文本框 /为各个按钮添加监听函数 bAdd.addActionListener(this); bDel.ad

14、dActionListener(this); bLastYear.addActionListener(this); bNextYear.addActionListener(this); bLastMonth.addActionListener(this); bNextMonth.addActionListener(this); /将按钮添加到Jpanel上 p1.add(bLastYear); p1.add(jtfYear);/年份输入文本框 p1.add(bNextYear); p1.add(bLastMonth); p1.add(jtfMonth); p1.add(bNextMonth);

15、 p2.add(bAdd); p2.add(bDel); p3.add(jsp, BorderLayout.CENTER); p3.add(p2, BorderLayout.SOUTH); p3.add(ld, BorderLayout.NORTH); p4.add(l); p4.add(lt); p5.add(p4, BorderLayout.SOUTH); p5.add(sp, BorderLayout.CENTER); p5.add(p1, BorderLayout.NORTH); this.getContentPane().add(p5, BorderLayout.CENTER); t

16、his.getContentPane().add(p3, BorderLayout.EAST); String strDate = DateFormat.getDateInstance().format(new Date().split(-);/取得日期 cld.set(Integer.parseInt(strDate0), Integer.parseInt(strDate1)-1, 0); showCalendar(Integer.parseInt(strDate0), Integer.parseInt(strDate1), cld); jtfMonth.setEditable(false)

17、;/设置月份文本框为不可编辑 jtfYear.setText(strDate0); jtfMonth.setText(strDate1); this.showTextArea(strDate2); ld.setFont(new Font(新宋体,Font.BOLD,24); new Timer(lt).start(); this.setBounds(200,200,600,320); this.setResizable(false); this.setVisible(true);3.4 触发器 public void actionPerformed(ActionEvent e) if(e.ge

18、tSource() = jtfYear | e.getSource() = bLastYear | e.getSource() = bNextYear | e.getSource() = bLastMonth | e.getSource() = bNextMonth) int m, y; try/控制输入年份正确,异常控制 if (jtfYear.getText().length() != 4) throw new NumberFormatException(); y = Integer.parseInt(jtfYear.getText(); m = Integer.parseInt(jtfM

19、onth.getText(); catch (NumberFormatException ex) JOptionPane.showMessageDialog(this, 请输入4位0-9数字!, 年份有误, JOptionPane.ERROR_MESSAGE); return; ld.setText(没有选择日期); for (int i = 0; i lastTime+1; i+) dtm.removeRow(0); if(e.getSource() = bLastYear) jtfYear.setText(String.valueOf(-y); if(e.getSource() = bNe

20、xtYear)jtfYear.setText(String.valueOf(+y); if(e.getSource() = bLastMonth) if(m = 1) jtfYear.setText(String.valueOf(-y); m = 12; jtfMonth.setText(String.valueOf(m); else jtfMonth.setText(String.valueOf(-m); if(e.getSource() = bNextMonth) if(m = 12) jtfYear.setText(String.valueOf(+y); m = 1; jtfMonth.

21、setText(String.valueOf(m); else jtfMonth.setText(String.valueOf(+m); cld.set(y, m-1, 0); showCalendar(y, m, cld); if(e.getSource() = bAdd) int r = table.getSelectedRow(); int c = table.getSelectedColumn(); if(!ld.getText().equals(没有选择日期) try File file = new File(ld.getText() + .txt); BufferedWriter

22、bw=new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file); bw.write(jta.getText(); bw.close(); catch (FileNotFoundException ex) ex.printStackTrace(); catch (IOException ex) ex.printStackTrace(); if(e.getSource() = bDel) int r = table.getSelectedRow(); int c = table.getSelectedColumn();

23、 File filedel = new File(ld.getText() + .txt); if(filedel.exists() if(filedel.delete() jta.setText(日志删除成功); else jta.setText(日志删除失败); else jta.setText(没有找到日志文件); public void mouseClicked(MouseEvent e) jta.setText(null); int r = table.getSelectedRow(); int c = table.getSelectedColumn(); if (table.get

24、ValueAt(r,c) = null) ld.setText(没有选择日期); else this.showTextArea(table.getValueAt(r,c); public void mousePressed(MouseEvent e) public void mouseReleased(MouseEvent e) public void mouseEntered(MouseEvent e) public void mouseExited(MouseEvent e) private void showTextArea(Object selected) /将所选日期显示出来,能不能

25、弄成农历显示 ld.setText(jtfYear.getText()+年+jtfMonth.getText()+月+selected+日); File filein = new File(ld.getText() + .txt); if(filein.exists() try BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(filein); String strRead = br.readLine(); jta.setText(null); while(strRead != nu

26、ll) jta.append(strRead); strRead = br.readLine(); br.close(); catch (FileNotFoundException ex) ex.printStackTrace(); catch (IOException ex) ex.printStackTrace(); 3.5时间获取class Timer extends Thread/显示系统时间 private JLabel lt; private SimpleDateFormat fy = new SimpleDateFormat(yyyy.MM.dd G at HH:mm:ss z)

27、; private SimpleDateFormat fn = new SimpleDateFormat(yyyy.MM.dd G at HH mm ss z); private boolean b = true; public Timer(JLabel lt) this.lt = lt; public void run() while (true) try if (b) lt.setText(fy.format(new Date(); else lt.setText(fn.format(new Date(); b = !b; this.sleep(500); catch (Interrupt

28、edException ex) ex.printStackTrace(); 4测试分析 图4-1 图4-2 图4-3 图4-4 对程序进行正常使用,测试各项功效实现过程是否存在bug,经测试,软件正常使用,无任何Bug。5源程序清单import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.MouseEvent;import java.awt.event.MouseListener;import java.io.BufferedRea

29、der;import java.io.BufferedWriter;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStreamReader;import java.io.OutputStreamWriter;/import java.sql.Date;import java.text.DateFormat;im

30、port java.text.SimpleDateFormat;import java.util.Calendar;import java.util.Date;import javax.swing.JButton;import javax.swing.JDialog;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.JTable;

31、import javax.swing.JTextArea;import javax.swing.JTextField;import javax.swing.table.DefaultTableModel;public class wannianli extends JFrame implements ActionListener, MouseListener private Calendar cld = Calendar.getInstance(); private String astr = 星期一, 星期二, 星期三, 星期四, 星期五, 星期六, 星期日; private Default

32、TableModel dtm = new DefaultTableModel(null,astr); private JTable table = new JTable(dtm); /装日期表格 private JScrollPane sp = new JScrollPane(table); private JButton bLastYear = new JButton(上十二个月); private JButton bNextYear = new JButton(下十二个月); private JButton bLastMonth = new JButton(上月); private JBu

33、tton bNextMonth = new JButton(下月); private JTextField jtfYear = new JTextField(5);/jtfYear年份显示和输入文本框 private JTextField jtfMonth = new JTextField(2);/jtfMonth月份显示文本框 private JPanel p1 = new JPanel(); /装入控制日期按钮模块 private JPanel p2 = new JPanel(); private JPanel p3 = new JPanel(new BorderLayout(); pri

34、vate JPanel p4 = new JPanel(new GridLayout(2,1); private JPanel p5 = new JPanel(new BorderLayout(); private JButton bAdd = new JButton(保留日志); private JButton bDel = new JButton(删除日志); private JTextArea jta = new JTextArea(); /jta-JTextArea private JScrollPane jsp = new JScrollPane(jta); private JLab

35、el l = new JLabel(年份文本框中可直接键入要查找年份,以提升查询效率); private JLabel lt = new JLabel(); private JLabel ld = new JLabel(); private int lastTime; public wannianli() super(万年历); /框架命名 this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);/窗口关闭函数 this.getContentPane().setLayout(new BorderLayout(10, 0); jta.setLineWrap(true); table.setGridColor(Color.GRAY); /星期之间网格线是灰色 table.setColumn

展开阅读全文
相似文档                                   自信AI助手自信AI助手
猜你喜欢                                   自信AI导航自信AI导航
搜索标签

当前位置:首页 > 学术论文 > 其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        获赠5币

©2010-2024 宁波自信网络信息技术有限公司  版权所有

客服电话:4008-655-100  投诉/维权电话:4009-655-100

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :gzh.png    weibo.png    LOFTER.png 

客服