java-万年历课程设计报告
Java万年历课程设计报告

杭州师范大学钱江学院课程设计题目万年历学院钱江学院专业信电分院计算机科学与技术班级计算机1101姓名崔伊平指导教师王李冬2013 年9 月20 日目录一.概述 (1)二.总体方案设计 (2)三.详细设计 (3)四.最终输出 (7)五.课程设计总结 (8)参考文献 (9)一、概述1.课程设计的目的通过显示年日历程序的设计,培养学生综合利用java语言进行程序设计的能力,加强函数的运用及学生对软件工程方法的初步认识,提高软件系统分析能力和程序文档建立、归纳总结的能力。
通过本项课程设计,可以培养独立思考、综合运用所学有关相应知识的能力,能更好的巩固《java语言程序设计》课程学习的内容,掌握工程软件设计的基本方法,强化上机动手编程能力,闯过理论与实践相结合的难关!更加了解了java语言的好处和其可用性!2.课程设计的要求2.1输入查询的年份与月份,单击“更新”按扭,则可得到相应的日历。
本实验是对图形用户界面,布局管理器的综合运用。
要掌握APPLET容器中添加组件的方法,理解JAVA 的事件处理机制,编写独立的运行窗口。
2.2 输出形式使用独立的运行窗口进行显示。
界面主要由两部分组成——查询输入部分和结果显示部分。
查询输入部分包括两个文本域,一个用于输入年份:一个用于选择月份:一个更新按扭,用来触发查询事件。
二总体方案设计1.程序开发环境a.开发环境:eclipseb.系统环境:windows xp/7c.设计工具:Microsoft office 20032.整体流程图图1 流程图3.功能模块图图2 结构图三.详细设计3.1导入的包import java.applet.*;import java.awt.*;import java.awt.event.*;import java.util.*;3.2Applet的初始化public void init(){Label L1 = new Label("输入年份");Label L2 = new Label("输入月份");TextField F1 = new TextField(5);TextField F2 = new TextField(5);Button B1 = new Button("查询");int arr = new int[12];add(L1);add(F1);add(L2);add(F2);add(B1);Date date = new Date();F1.setText(String.valueOf(date.getYear() + 1900));F2.setText(String.valueOf(date.getMonth() + 1));B1.addActionListener(this);arr[0] = arr[2] = arr[4] = arr[6] = arr[7] = arr[9] = arr[11] = 31; arr[3] = arr[5] = arr[8] = arr[10] = 30;date.setDate(1);//设置每月第一天var = date.getDay();//得到每月最后一天}3.3监听器public void actionPerformed(ActionEvent e) {int x = Integer.parseInt(F1.getText()), i = Integer.parseInt(F2.getText()) - 1, s = 0;if(F1.getText().isEmpty()||F2.getText().isEmpty()){JOptionPane.showMessageDialog(null,"输入不能为空!");}Date date = new Date();date.setYear(x - 1900);date.setMonth(i);date.setDate(1);var = date.getDay();repaint();}3.3paint()public void paint(Graphics g) {int xpos, ypos;//arr[0] = arr[2] = arr[4] = arr[6] = arr[7] = arr[9] = arr[11] = 31; //arr[3] = arr[5] = arr[8] = arr[10] = 30;int x = Integer.parseInt(F1.getText()), i = Integer.parseInt(F2.getText()) - 1;if ((x % 4 == 0 && x % 100 != 0) || (x % 400 == 0))arr[1] = 29;elsearr[1] = 28;g.drawString("星期一", 50, 50);g.drawString("星期二", 100, 50);g.drawString("星期三", 150, 50);g.drawString("星期四", 200, 50);g.drawString("星期五", 250, 50);g.drawString("星期六", 300, 50);g.drawString("星期日", 350, 50);ARR = new String[arr[i]];int j = 0, k = 1;while (k <= arr[i]) {ARR[j] = String.valueOf(k);//获得每个月日期k ++;j ++;}int line = 0;for (int m = 0 ; m < ARR.length ; m ++) { //设置日期显示的位置ypos = 50 + 50 * (line + 1);xpos = (var * 50 + 50 * (m % 7)) % 350;if (xpos == 0) {xpos = 350;line ++;}g.drawString(ARR[m], xpos, ypos);}}}四.最终输出1.输入年月界面2.显示界面4.输入为空情况五.课程设计总结在最初设计这个程序的时候走了不少弯路,一开始对Applet程序没有深入理解,就把初始化部分写到构造函数里去了,后来在老师的提醒下,自己修改过来了。
Java万年历课程设计报告

Java课程设计设计题目:万年历系别:计算机科学与工程学院专业:信息管理与信息系统学号:姓名:岑少兵指导教师:汪华澄时间: 2013-6-29目录摘要 (3)系统功能结构图 (3)1 系统模块设计 (4)1.1 需求设计 (4)1.2 开发和运行环境 (4)1.3 功能设计 (4)2 万年历详细设计思路 (4)2.1 程序设计思路 (5)2.2 程序运行主界面 (5)2.3 流程图 (6)3 各模块功能实现及代码说明 (6)3.1 MainFramel类 (6)3.2 Lunar类 (14)3.3 national类 (22)3.4 SetClock类 (26)4 小结 (34)5 参考文献 (34)基于Myeclipse的万年历摘要:万年历是日常生活中不可或缺的小工具,用万年历我们可以准确地查到当前,以后或是过去的日期,极大地方便了我们的生活。
在万年历上添加了显示本地时间以后会更加准确地显示时间。
无论是对于我们学生还是上班族或是自由职业者需要经常查看和查找万年历来规划自己将要做得一些事情,或是回忆在过去的时间里已经做过的事情,使之更加有利于提升我们的学习或是工作进度。
系统功能结构图:主要描述系统要实现的各个模块的功能。
1系统模块设计1.1需求分析本程序的要求为:1.使用图形用户界面2.能够实现日期与星期的查询3.能够显示农历4.能够查看世界时间5.能够添加闹钟1.2 开发和运行环境开发工具:Myeclipse运行环境: windows 71.3功能设计本程序要构建的万年历程序,其功能有以下几个方面:(1)通过(2)提供年份、月份的下拉形式菜单来选择年份和月份。
(3)通过Lunar类实现农历日期。
(4)通过national类实现世界时间。
(5)能以月历形式显示日期与星期。
(6)通过SetClock类来实现闹钟功能。
(7)通过点击世界时间按钮查询世界时间(8)通过点击闹钟按钮设置闹钟(9)显示系统当前时间和日期。
java课程设计报告之万年历程序设计报告(1)

目录前言 (2)1需求分析 (2)1.1需求分析 (2)1.2功能设计 (2)2.概要设计 (2)2.1程序设计思路 (2)2.2程序运行界面 (3)2.3流程图 (4)3.各模块的功能及程序说明 (4)3.1.初始化组件 (4)3.2.初始化数据 (5)3.3.绘制程序界面 (5)4.测试分析 (7)5.源程序清单 (9)6.课程设计体会 (17)参考文献 (17)前言Java的前身是Oak,它一开始只是被应用于消费性电子产品中。
后来它的开发者们发现它还可以被用于更大范围的Internet上。
1995年,Java语言的名字从Oak编程了Java。
1997年J2SE1.1发布。
1998年J2SE1.2发布,标志Java2的诞生。
十多年来,Java编程语言及平台成功地运用在网络计算及移动等各个领域。
Java的体系结构由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是大多开发工具的基础。
以上的每种开发工具都有优缺点,对于开发者来说,重要的是要根据自己的开发规模、开发内容和软硬件环境等因素来选择一种合适的开发工具。
1需求分析1.1需求分析本程序的要求为:1.使用图形用户界面;2.本程序能够实现日期与星期的查询。
1.2功能设计本程序要构建的万年历程序,其功能有以下几个方面:(1)通过网页形式运行,实现图形界面。
java万年历设计报告

JAVA大作业目录作业要求 (3)项目概述 (3)具体功能介绍 (4)设计与实现 (4)作业要求:编写一个万年历程序,要求能够查询历史时间,能够添加、查看、删除备忘录。
项目概述这个项目是一个简单的Java万年历,可以实现所有年份的公历日期的查询,并且在相应的日期做备忘录,以及可以显示当前的日期以及时间。
使用的是Oracle数据库进行连接。
具体功能介绍:(1)万年历查询:点击图形界面中的上年、下年键用来调整要查询的年份,或者可以直接在上年下年按钮直接的文本框中输入年份(负数表示公元前),以回车结束;点击上月或者下月来调整要查询的月份,然后可以看到这个月的每一天所对应的星期。
(2)Clock功能:在万年历下面显示当前的年月日时分秒,相当于一个时钟的功能。
(3)记事本功能:可以任选某年某月的某一天,单击,在右侧会出现这一天的备忘录,如果存在,则显示某年某月某日有日志记载,是否想看,否则,则在文本框中显示无记录;然后可以编辑这一天的备忘录,编辑好了之后,点击保存日志,弹出对话框某年某月某日保存日志吗,点击保存,则日志被保存,反之未被保存;若想删除某日的日志,则单击这一天,然后点击右侧的删除日志,显示删除某年某月某日的日志吗,点击是,则日志被删除。
从文件中读取备忘录的内容,用数据库进行存储和删除操作。
设计与实现(需要附全部代码,GUI自动生成代码除外):1 类的设计(继承、多态、数据结构):核心类是Month,Year,NotePad,Clock,DBAccess,CalendarPad.(其中继承用粗体,接口用粗斜体,数据结构是哈希表,用粗下划线,多态用斜体+点点短线式下划线)2 Java IO (文件访问):用的是粗体+浪线3 JDBC (数据库访问):使用Oracle数据库连接,是直连(双下划线)数据库是:create table mynotes(mydate varchar2(50) primary key,note varchar2(100) not null);4 Socket + Multi-Thread:斜体(定义在Clock中的Thread t)5 GUI (用户界面):点下划线来表示GUI用户界面6 其他功能:(无)以下是全部代码(共六个.Java文件)//对月份的选择package javaapplication13;import javax.swing.*;import java.awt.*;import java.awt.event.*;public class Month extends Box implements ActionListener//ActionListener接口{int month;JTextField showMonth=null;JButton RMonth,NMonth;CalendarPad cal;public Month(CalendarPad c){super(BoxLayout.X_AXIS);this.cal=c;showMonth=new JTextField(2);month=c.getMonth();showMonth.setEditable(false);showMonth.setForeground(Color.blue);showMonth.setFont(new Font("TimesRomn",Font.BOLD,16));NMonth=new JButton("下月");RMonth=new JButton("上月");add(RMonth);add(showMonth);add(NMonth);RMonth.addActionListener(this);NMonth.addActionListener(this);showMonth.setText(""+month);}public void setMonth(int month){if(month<=12&&month>=1){this.month=month;}else{this.month=1;}showMonth.setText(""+month);}public int getMonth(){return month;}public void actionPerformed(ActionEvent e){if(e.getSource()==RMonth){if(month>=2){month=month-1;cal.setMonth(month);cal.setCal(cal.getYear(),month);}else if(month==1){month=12;cal.setMonth(month);cal.setCal(cal.getYear(),month);}showMonth.setText(""+month);}else if(e.getSource()==NMonth){if(month<12){month=month+1;cal.setMonth(month);cal.setCal(cal.getYear(),month);}else if(month==12){month=1;cal.setMonth(month);cal.setCal(cal.getYear(),month);}showMonth.setText(""+month);}}}//对年分的选择package javaapplication13;import javax.swing.*;import java.awt.*;import java.awt.event.*;public class Year extends Box implements ActionListener//ActionListener接口{int year;JTextField showYear=null;JButton NYear,RYear;CalendarPad cal;public Year(CalendarPad c){super(BoxLayout.X_AXIS);showYear=new JTextField(4);showYear.setForeground(Color.blue);showYear.setFont(new Font("TimesRomn",Font.BOLD,14));this.cal=c;year=cal.getYear();NYear=new JButton("下年");RYear=new JButton("上年");add(RYear);add(showYear);add(NYear);showYear.addActionListener(this);RYear.addActionListener(this);NYear.addActionListener(this);}public void setYear(int year){this.year=year;showYear.setText(""+year);}public int getYear(){return year;}public void actionPerformed(ActionEvent e){if(e.getSource()==RYear){year=year-1;showYear.setText(""+year);cal.setYear(year);cal.setCal(year,cal.getMonth());}else if(e.getSource()==NYear){year=year+1;showYear.setText(""+year);cal.setYear(year);cal.setCal(year,cal.getMonth());}else if(e.getSource()==showYear){try{year=Integer.parseInt(showYear.getText());showYear.setText(""+year);cal.setYear(year);cal.setCal(year,cal.getMonth());}catch(NumberFormatException ee){showYear.setText(""+year);cal.setYear(year);cal.setCal(year,cal.getMonth());}}}}//对备忘录的操作package javaapplication13;import java.awt.*;import java.awt.event.*;import java.util.*;import javax.swing.*;import javax.swing.event.*;import java.io.*;public class NotePad extends JPanel implements ActionListener {JTextArea text;JButton save_log,del_log;Hashtable table;JLabel mes_label;int year,month,day;File file;CalendarPad calendar;public NotePad(CalendarPad calendar)//构造函数{this.calendar=calendar;Calendar now = Calendar.getInstance();int hour=now.get(Calendar.HOUR);int minute=now.get(Calendar.MINUTE);year=calendar.getYear();month=calendar.getMonth();day=calendar.getDay();;table=calendar.getHashtable();file=calendar.getFile();mes_label=new JLabel(""+year+"年"+month+"月"+day+"日"+" "+hour+":"+minute,JLabel.CENTER);mes_label.setFont(new Font("TimesRoman",Font.BOLD,16));mes_label.setForeground(Color.MAGENTA);text=new JTextArea(10,8);save_log=new JButton("保存日志") ;del_log=new JButton("删除日志") ;save_log.addActionListener(this);del_log.addActionListener(this);setLayout(new BorderLayout());JPanel pSouth=new JPanel();add(mes_label,BorderLayout.NORTH);pSouth.add(save_log);pSouth.add(del_log);add(pSouth,BorderLayout.SOUTH);add(new JScrollPane(text),BorderLayout.CENTER);}public void actionPerformed(ActionEvent e){if(e.getSource()==save_log){saveLog(year,month,day);}else if(e.getSource()==del_log){delLog(year,month,day);}}public void setYear(int year){this.year=year;}public int getYear(){return year;}public void setMonth(int month){this.month=month;}public int getMonth(){return month;}public void setDay(int day){this.day=day;}public int getDay(){return day;}public void setMesLabel(int year,int month,int day){mes_label.setText(""+year+"年"+month+"月"+day+"日");}public void setText(String s){text.setText(s);}public void getLog(int year,int month,int day){String key=""+year+""+month+""+day;try{FileInputStream inOne=new FileInputStream(file);ObjectInputStream inTwo=new ObjectInputStream(inOne);table=(Hashtable)inTwo.readObject();inOne.close();inTwo.close();}catch(Exception ee){}if(table.containsKey(key)){String m=""+year+"年"+month+"月"+day+"这一天有日志记载,想看吗?";int ok=JOptionPane.showConfirmDialog(this,m,"询问",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE);if(ok==JOptionPane.YES_OPTION){text.setText((String)table.get(key));}else{text.setText("");}}else{text.setText("无记录");}}public void saveLog(int year,int month,int day){String 日志内容=text.getText();String key=""+year+""+month+""+day;String m=""+year+"年"+month+"月"+day+"保存日志吗?";int ok=JOptionPane.showConfirmDialog(this,m,"询问",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE);if(ok==JOptionPane.YES_OPTION){try{FileInputStream inOne=new FileInputStream(file);ObjectInputStream inTwo=new ObjectInputStream(inOne);table=(Hashtable)inTwo.readObject();inOne.close();inTwo.close();table.put(key,日志内容);FileOutputStream out=new FileOutputStream(file);ObjectOutputStream objectOut=new ObjectOutputStream(out);objectOut.writeObject(table);objectOut.close();out.close();}catch(Exception ee){}}//向数据库中添加数据。
JAVA课程设计--基于JAVA的万年历设计与实现

JAVA课程设计--基于JAVA的万年历设计与实现Java课程设计报告:万年历课程设计题目:万年历指导老师:**********学生姓名:*********专业:**********学号:*******1.课程设计目的本学期我们研究了Java语言,它是当今世界最流行的开发语言之一,具有面向对象、跨平台、分布应用等特点。
为了巩固所学知识,锻炼学生熟练应用面向对象的思想和设计方法解决实际问题的能力,开设了Java程序设计课程设计。
本次课程设计要求我们利用已学的Java知识,编辑一个电子万年历,通过自主研究和实践,将理论变成实践,将知识真正学以致用。
2.需求分析2.1 本程序要求本程序要使用图形用户界面,能够实现日期与星期查询,同时显示此时的时间。
2.2 功能设计本程序要构建万年历程序,其功能如下:1) 通过窗口形式运行,实现界面功能;2) 以月历的形式来显示日期与星期;3) 为用户提供年份与月份的下拉形式菜单,选择年份与月份;4) 同时显示查看时的时刻。
3.课程设计的基本算法在Java程序中,通过定义中英文字符数组来存储星期信息,用于转换显示。
同时,使用Date类和GregorianCalendar 类来获取日期和时间信息,实现万年历的功能。
以上是本次Java课程设计的基本内容和算法,通过此次实践,我们巩固了Java语言的基本知识,掌握了JDK、JCreator等开发工具的运用,拓宽了常用类库的应用,对Java这门课程有了更深的了解和认识。
public class DateUtil {private static final String[] stringWeekEn = {"Sun"。
"Mon"。
"Tue"。
"Wed"。
"Thu"。
"Fri"。
"Sat"};private static final String[] stringMonthEn = {"Jan"。
java程序设计报告2万年历

程序设计报告JA V A设计报告2:万年历姓名:王颖学号:001学习中心:延安富县学习中心专业:计算机科学与技术层次:专升本身份证号:联系电话:万年历程序设计一、设计分析万年历有很多作用,顾名思义它是一种很方便得计时计年工具,随着科技得发展,我们已经可以通过计算机制作出精美的万年历,通过计算机制作得万年历不但外观美观,而且功能强大。
通过万年历,我们可以实现很多功能,随意看某年得年份,某年得月份,随意调整某年得某天,并将其显示出来,而且有判断闰年闰月得功能,十分方便。
二、程序流程框图主程序流程图三、具体设计1、变量设计2、程序源代码import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.event.*;import javax.swing.border.*;import java.util.Calendar;import java.util.*;import java.io.*;import java.io.IOException;public class calendar extends JFrame implements ActionListener,MouseListener {int year,month,day;int yearafterquery,monthafterquery;int startday;String SwitchMonth;String key;int changeyearmessage;int changemonthmessage;int priormonth;int prioryear;boolean ischange=false;boolean ischange_priornext=false; private JPanel LeftPane,RightPane;//Left subprivate JLabel YearLabel;private JComboBox MonthCombobox;private JTextField ShowDays[]= new JTextField[42];private JTextField YearText;private JLabel Ask;private JLabel ShowDate;private JLabel Blank;private JLabel TopBarTitle[]=new JLabel[7];private JButton ToToday;private JButton Query;privateString week[]={"SUN","MON","TUE","WED","THU","FRI","SAT"};//right subprivate JLabel NorthMonthDayYear;private JTextArea CenterText;private JButton SouthSave,SouthDelete;private JButton PriorMonth;private JButton NextMonth;public calendar(int year,int month,int day){setTitle("My Calendar&Textbook");//the layout about left of jpaneLeftPane = new JPanel();JPanel LeftCenter = new JPanel();JPanel LeftNorth = new JPanel();//JPanel LeftSouth = new JPanel();LeftPane.setLayout(new BorderLayout());LeftPane.add(LeftNorth,BorderLayout.NORTH);LeftPane.add(LeftCenter,BorderLayout.CENTER);LeftPane.add(ToToday = new JButton("Go to today",new ImageIcon("../images/Handle.gif")),BorderLayout.SOUTH);ToToday.setBackground(Color.cyan);ToToday.addActionListener(this);LeftPane.validate();//the layout of LeftPane//LeftPane_NorthLeftNorth.setLayout(new GridLayout(3,1,0,-2));LeftNorth.add(Ask = new JLabel(" Plese input the informations which you want query:"));JPanel North = new JPanel(new FlowLayout(0,8,0));LeftNorth.add(North);North.add(YearLabel=new JLabel("Year:"));North.add(YearText = new JTextField(4));YearText.setBackground(Color.getHSBColor(30,20,50));YearText.setForeground(Color.blue);YearText.setFont(new Font("TimesRoman",Font.BOLD,17));YearText.setFocusable(true);North.add(Blank=new JLabel(" "));North.add(MonthLabel = new JLabel("Month:"));North.add(MonthCombobox = new JComboBox());//add month to monthcomboboxfor(int i=1;i<=12;i++){MonthCombobox.addItem(new Integer(i));}//Switch the monthMonthCombobox.setForeground(Color.blue);MonthCombobox.setFont(new Font("TimesRoman",Font.BOLD,12));North.add(Blank=new JLabel(" "));North.add(Query=new JButton("Query"));Query.setForeground(Color.blue);Query.addActionListener(this);JPanel North2=new JPanel(new FlowLayout());LeftNorth.add(North2);North2.add(PriorMonth=new JButton(new ImageIcon("../images/prior.gif")));PriorMonth.addActionListener(this);PriorMonth.setActionCommand("prior");priormonth=month;prioryear=year;SwitchMonth(month);North2.add(ShowDate = new JLabel(SwitchMonth+" "+","+" "+String.valueOf(year),SwingConstants.CENTER));ShowDate.setForeground(Color.blue);ShowDate.setFont(new Font("TimesRoman",Font.BOLD,14));North2.add(NextMonth=new JButton(new ImageIcon("../images/next.gif")));NextMonth.addActionListener(this);NextMonth.setActionCommand("next");//LeftPane_CenterLeftCenter.setLayout(new GridLayout(7,7));//print titlefor(int i=0;i<7;i++){TopBarTitle[i]=new JLabel();TopBarTitle[i].setText(week[i]);TopBarTitle[i].setForeground(Color.darkGray);TopBarTitle[i].setHorizontalAlignment(0);TopBarTitle[i].setBackground(Color.MAGENTA );TopBarTitle[i].setBorder(BorderFactory.createRaisedBevelBorder());LeftCenter.add(TopBarTitle[i]);}for(int i=0;i<42;i++){ShowDays[i]=new JTextField();ShowDays[i].addMouseListener(this);ShowDays[i].setEditable(false);LeftCenter.add(ShowDays[i]);}//print the body of monthPrintMonth(year,month,day);//the layout about right of jpaneRightPane = new JPanel(new BorderLayout());JPanel RightCenter = new JPanel();JPanel RightNorth = new JPanel();JPanel RightSouth = new JPanel(new FlowLayout());RightPane.add(RightNorth,BorderLayout.NORTH);RightPane.add(RightCenter,BorderLayout.CENTER);RightPane.add(RightSouth,BorderLayout.SOUTH);RightNorth.add(NorthMonthDayYear=new JLabel(">>"+year+","+SwitchMonth+","+day+"<<")); key=year+"_"+SwitchMonth+"_"+day;NorthMonthDayYear.setForeground(Color.blue);NorthMonthDayYear.setFont(new Font("TimesRoman",Font.BOLD,17));RightCenter.add(CenterText=new JTextArea("please write today's things."));CenterText.setLineWrap(true);CenterText.setSelectedTextColor(Color.blue);//CenterText.addActionListener(this);RightSouth.add(SouthSave=new JButton(" Save "));SouthSave.setBackground(Color.cyan);SouthSave.addActionListener(this);SouthSave.setActionCommand("Save");RightSouth.add(SouthDelete=new JButton(" Delete "));SouthDelete.setBackground(Color.cyan);SouthDelete.addActionListener(this);SouthDelete.setActionCommand("Delete");this.year = year;this.month = month;this.day = day;///add container to put LeftPane and RightPaneContainer con=getContentPane();JSplitPane split=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,RightPane,LeftPane);//gai bian con.add(split,BorderLayout.CENTER);con.validate();//add CenterPane to notepad//CenterPane initializesetFont(new Font("Times New Roman",Font.PLAIN,12));JScrollPane scrollpane = new JScrollPane(CenterText); scrollpane.setPreferredSize(new Dimension(220,250)); RightCenter.add(scrollpane);//init randomaccessfile}//switch the month in englishpublic void SwitchMonth(int month){switch(month){case 1:SwitchMonth="Jan";break;case 2:SwitchMonth="Feb";break;case 3:SwitchMonth="Mar";break;case 4:SwitchMonth="Apr";break;case 5:SwitchMonth="May";break;case 6:SwitchMonth="Jun";break;case 7:SwitchMonth="Jul";break;case 8:SwitchMonth="Aug";break;case 9:SwitchMonth="Sep";break;case 10:SwitchMonth="Qct";break;case 11:SwitchMonth="Nov";break;case 12:SwitchMonth="Dec";break;}}//print the body of the monthpublic void PrintMonth(int year,int month,int day){//Get start day of the week for the first date in the month int startday = GetStartDay(year,month);//Get number of days in the monthint dayinmonth = GetNumOfDaysInMonth(year,month); //Print header//Print bodyPrintMonthBody(startday,dayinmonth,day);}//PrintMonth(int year,int month,int day)'s burdenpublic void PrintMonth(int year,int month){//Get start day of the week for the first date in the monthint startday = GetStartDay(year,month);//Get number of days in the monthint dayinmonth = GetNumOfDaysInMonth(year,month);//Print header//Print bodyPrintMonthBody(startday,dayinmonth);}//PrintMonthBody(int startday,int dayinmonth,int day)'s burden public void PrintMonthBody(int startday,int dayinmonth){for(int i=startday,n=1;i<startday+dayinmonth;i++){ShowDays[i].setText(""+n);ShowDays[i].setHorizontalAlignment(0);//let centerif(n==day){ShowDays[i].setForeground(Color.green);ShowDays[i].setFont(new Font("TimesRoman",Font.BOLD,20)); ShowDays[i].setBackground(Color.DARK_GRAY);}else{ShowDays[i].setFont(new Font("TimesRoman",Font.BOLD,12)); ShowDays[i].setForeground(Color.white);ShowDays[i].setBackground(Color.DARK_GRAY);}n++;}for(int i=0;i<startday;i++){ShowDays[i].setText("");ShowDays[i].setBackground(Color.DARK_GRAY);}for(int i=startday+dayinmonth;i<42;i++){ShowDays[i].setText("");ShowDays[i].setBackground(Color.DARK_GRAY);}//judge leapyear is or notpublic boolean IsLeapYear(int year){if((year%400==0)||(year%4==0&&year%100!=0))return true;elsereturn false;}//judge the start day of a monthpublic int GetStartDay(int year,int month){//get total number of day since1/1/0000int startday0001=-32768;long totalnumofdays=GetTotalNumOfDays(year,month);//return the start dayreturn (int)((totalnumofdays+startday0001)%7);}//judge the days of a yearpublic long GetTotalNumOfDays(int year,int month){long total=0;//get the total days from -32767 to yearfor(int i=-32767;i<year;i++){if(IsLeapYear(i))total=total+366;elsetotal=total+365;}//Add days from jan to the month prior to the calendar monthfor(int i=1;i<month;i++)total=total+GetNumOfDaysInMonth(year,i);return total;}//judge the days of a monthpublic int GetNumOfDaysInMonth(int year,int month){if(month==1 || month==3 || month==5 || month==7 || month==8 || month==10 ||month==12) return 31;if(month==4 || month==6 || month==9 || month==11)return 30;if(month==2)if(IsLeapYear(year))return 29;elsereturn 28;}return 0;}public void WriteRecord(){String content;content=CenterText.getText();int n=content.length();char[] contentarr=new char[n];try{int i=0;for(i=0;i<n;i++){contentarr[i]=content.charAt(i);}File Diary = new File("Diary");Diary.mkdir();File myfile=new File("Diary\\"+key+".txt"); FileWriter Record=new FileWriter(myfile);for(i=0;i<contentarr.length;i++){Record.write(contentarr[i]);}Record.close();JOptionPane.showMessageDialog(this,"Save success!");}catch(IOException ex){}}public void ReadRecord(){try{String content="";File myfile=new File("Diary\\"+key+".txt"); FileReader Record=new FileReader(myfile);if(myfile.exists())long b=myfile.length();//char[] contentarr=new char[b];int n=JOptionPane.showConfirmDialog(this,"Today has logs,are you read?","Confirm",JOptionPane.YES_NO_CANCEL_OPTION);if(n==JOptionPane.YES_OPTION){while((b=Record.read())!=-1){content=content+(char)b;}CenterText.setText(content);}}Record.close();}catch(IOException ex){CenterText.setText("Today has not logs.");}}public void DeleteFile(){String filepath="Diary\\"+key+".txt";File myfile=new File(filepath);int n=JOptionPane.showConfirmDialog(this,"Are you sure delete the file?","Confirm",JOptionPane.YES_NO_CANCEL_OPTION);if(n==JOptionPane.YES_OPTION){if(myfile.exists()){Runtime rt = Runtime.getRuntime();try{rt.exec("cmd /c del "+filepath);}catch (IOException e){e.printStackTrace();}JOptionPane.showMessageDialog(this,"Delete successed!");CenterText.setText("Today has not logs.");}elseJOptionPane.showMessageDialog(this,"The file doesn't exist,delete failured!");}}}public void AboutActionListenerWay(){try{prioryear=Integer.parseInt(YearText.getText());priormonth=MonthCombobox.getSelectedIndex()+1;String StrYearText=YearText.getText();changeyearmessage=Integer.parseInt(StrYearText);changemonthmessage=MonthCombobox.getSelectedIndex()+1;monthafterquery=changemonthmessage;yearafterquery=changeyearmessage;SwitchMonth(changemonthmessage);ShowDate.setText(SwitchMonth+" "+","+" "+String.valueOf(changeyearmessage));PrintMonth(changeyearmessage,changemonthmessage);ischange=true;}catch(Exception ee){JOptionPane.showMessageDialog(this,"The input format doesn't match","Error",JOptionPane.ERROR_MESSAGE);}}//do actonlistener thingspublic void actionPerformed(ActionEvent eAction){String ActionCommand=eAction.getActionCommand();//Handle button eventsif(eAction.getSource() instanceof JButton){//Handle the queryif("Query".equals(ActionCommand)){try{AboutActionListenerWay();}catch(Exception ee){JOptionPane.showMessageDialog(this,"The input format doesn't}}//Handle prior monthif("prior".equals(ActionCommand)){if(priormonth>1){priormonth=priormonth-1;}else{priormonth=12;prioryear=prioryear-1;}PrintMonth(prioryear,priormonth,day);SwitchMonth(priormonth);ShowDate.setText(SwitchMonth+" , "+prioryear);NorthMonthDayYear.setText(">>"+SwitchMonth+","+day+","+prioryear+"<<"); key=prioryear+"_"+SwitchMonth+"_"+day;ischange_priornext=true;}//Handle next monthif("next".equals(ActionCommand)){if(priormonth<12){priormonth=priormonth+1;}else{priormonth=1;prioryear=prioryear+1;}PrintMonth(prioryear,priormonth,day);SwitchMonth(priormonth);ShowDate.setText(SwitchMonth+" , "+prioryear);NorthMonthDayYear.setText(">>"+SwitchMonth+","+day+","+prioryear+"<<"); key=prioryear+"_"+SwitchMonth+"_"+day;ischange_priornext=true;}//Handle the "Go to today"if("Go to today".equals(ActionCommand)){YearText.setText("");MonthCombobox.setSelectedIndex(0);SwitchMonth(month);ShowDate.setText(SwitchMonth+" "+","+" "+String.valueOf(year)); NorthMonthDayYear.setText(">>"+year+SwitchMonth+","+day+","+"<<"); key=year+"_"+SwitchMonth+"_"+day;priormonth=month;prioryear=year;ischange=false;}//Handle the "Save"if("Save".equals(ActionCommand)){WriteRecord();}if("Delete".equals(ActionCommand)){DeleteFile();}}//Handle JTextField eventsif(eAction.getSource() instanceof JTextField){//Handle the queryAboutActionListenerWay();}}public void mousePressed(MouseEvent eMouse){int day;try{//Handle ShowDays[] eventsif(ischange==false){JTextField source=(JTextField)eMouse.getSource();day=Integer.parseInt(source.getText());if(ischange_priornext==false){NorthMonthDayYear.setText(">>"+SwitchMonth+","+day+","+year+"<<"); key=year+"_"+SwitchMonth+"_"+day;}elseNorthMonthDayYear.setText(">>"+SwitchMonth+","+day+","+prioryear+"<<");key=prioryear+"_"+SwitchMonth+"_"+day;}}elseJTextField source=(JTextField)eMouse.getSource();day=Integer.parseInt(source.getText());if(ischange_priornext==false){SwitchMonth(changemonthmessage);NorthMonthDayYear.setText(">>"+SwitchMonth+","+day+","+changeyearmessage+"<<"); key=changeyearmessage+"_"+SwitchMonth+"_"+day;}else{SwitchMonth(priormonth);NorthMonthDayYear.setText(">>"+SwitchMonth+","+day+","+prioryear+"<<");key=prioryear+"_"+SwitchMonth+"_"+day;}}ReadRecord();}catch(Exception ee){}}public void mouseClicked(MouseEvent e){}public void mouseReleased(MouseEvent e){}public void mouseEntered(MouseEvent e){}public void mouseExited(MouseEvent e){}public void SaveLog(int year,int month,int day){}public static void main(String[] args) throws Exception{int y=calendar.get(Calendar.YEAR);int m=calendar.get(Calendar.MONTH)+1;int d=calendar.get(Calendar.DAY_OF_MONTH);calendar frame = new calendar(y,m,d);frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.setSize(560,300);frame.setLocation(100,100);frame.setVisible(true);frame.setResizable(false);frame.ReadRecord();}}四、设计结果与分析4.1程序效果图程序打开时的效果,左边是记事本框,右边是万年历框。
用Java程序编写万年历程序的设计报告

用Java程序编写万年历程序的设计报告一、引言本文档是针对使用Java程序编写万年历程序的设计报告,旨在详细介绍该程序的设计思路和实现细节。
二、需求分析1.背景介绍在现代社会中,人们经常需要查看特定日期的日历信息。
为了方便用户直观地查看任意年月的日历信息,设计一个万年历程序,可以满足用户的需求。
2.功能需求万年历程序具备以下功能:●显示指定年月的日历信息●支持用户输入任意年月●能够高亮当前日期●具备简洁易读的界面设计3.性能需求●用户界面响应迅速,无明显卡顿●日历信息准确无误,支持闰年判断三、概要设计1.系统架构万年历程序采用MVC(Model.View.Controller)架构,将数据模型、用户界面和控制逻辑分离。
模型层:负责处理日期计算和数据存储视图层:负责展示日历信息,接收用户输入控制器层:负责协调模型层和视图层的交互2.关键模块●日历模块:负责日期计算,并提供接口给视图层调用●用户界面模块:提供用户交互界面,并接收用户输入●控制器模块:负责协调日历模块和用户界面模块四、详细设计1.日历模块设计●定义日期对象:包括年、月、日等属性●实现日期计算功能:如计算指定年月的第一天是星期几,判断某年是否为闰年等●提供接口给其他模块调用:如获取指定年月的日历信息2.用户界面设计●设计主界面:包括输入年月的文本框和显示日历信息的面板●设计按钮事件:响应用户输入的年月,调用日历模块计算并显示日历信息3.控制器设计●建立模型与视图之间的联系:将用户输入传递给日历模块,并将计算后的日历信息传递给视图层进行显示五、测试计划1.单元测试●对日历模块进行单元测试,测试日期计算功能的准确性●对用户界面模块进行单元测试,测试界面的交互和显示是否正常2.集成测试●测试控制器模块与日历模块、用户界面模块之间的功能协调是否正常六、附录1.附件●无2.法律名词及注释●无。
java课程设计万年历程序设计报告

山东科技大学信息学院JAVA程序设计学院:信息科学与工程学院班级:计算机 11-3学号:0230姓名:赵乐目录目录 (1)前言 (1)1需求分析 (2)2.概要设计 (3)3.各模块的功能及程序说明 (5)4.测试分析 (13)5.源程序清单 (13)6.课程设计体会 (22)前言Java的前身是Oak,它一开始只是被应用于消费性电子产品中。
后来它的开发者们发现它还可以被用于更大范围的Internet上。
1995年,Java语言的名字从Oak编程了Java。
1997年发布。
1998年发布,标志Java2的诞生。
十多年来,Java编程语言及平台成功地运用在网络计算及移动等各个领域。
Java的体系结构由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是大多开发工具的基础。
以上的每种开发工具都有优缺点,对于开发者来说,重要的是要根据自己的开发规模、开发内容和软硬件环境等因素来选择一种合适的开发工具。
1需求分析需求分析本程序的要求为:1.使用图形用户界面;2.本程序能够实现日期与星期的查询。
功能设计本程序要构建的万年历程序,其功能有以下几个方面:(1)通过网页形式运行,实现图形界面。
(2)能以月历形式显示日期与星期。
(3)支持用户自己输入年份,并提供月份的下拉形式菜单来选择月份。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
西安科技大学程序设计综合实训课程设计报告题目:万年历班级:学号:姓名:2103年12月目录1绪论 (1)1.1选题目的及意义 (1)1.2 系统概述 (1)1.3 人员组成及分工 (1)2 需求分析 (1)3 总体设计 (1)4 详细设计 (1)5 系统实现 (2)5.1 开发环境 (3)5.2 关键技术 (3)6.运行结果 (6)7.软件测试 (7)8.总结 (7)9 参考文献 (8)1.绪论1.1选题目的及意义选题目的:本次课程设计为课本后设计题目任选一题进行设计。
思考一段时间后,我们组决定做一个万年历的设计。
主要考虑到以前时间少课程内容多,JAVA课程基础内容掌握并不是很抓实,而对于设计一个万年历程序,由于其功能简单设计也相对较易,对于我们组每个人的学习情况比较合适,并且通过设计这样的一个日历小组件,也能使自己对JAVA 的一些基础知识掌握的更加牢固。
1.2 系统概述随着电子技术的不断发展,人们的不断创新,万年历已经不再局限于书本形式,而是以电脑软件或者电子产品的形式出现。
让其更加便捷。
在学习了JAVA课程后,将以JAVA 形式编译出一个简易的万年历。
1.3 人员组成及分工付磊:负责搜集查找资料王杜超:调试程序两人共同负责程序的编写与修改2.需求分析本程序的要求为:1.使用图形用户界面;2.本程序能够实现日期与星期的查询。
3.可以添加或者删除日志3.总体设计(1)可以通过图形界面显示日历。
(2)能以月历形式显示日期与星期。
(3)支持用户自己输入年份,可以通过上一年,下一年等按钮来选择年份和月份。
(4)可以添加或者删除并且点击对应日期显示日志。
4.详细设计1. 总天数的算法:首先用if语句判断定义年到输入年之间每一年是否为闰年,是闰年,该年的总天数为366,否则,为365。
然后判断输入的年是否为定义年,若是,令总天数S=1,否则,用累加法计算出定义年到输入年之间的总天数,再把输入年的一月到要输出的月份之间的天数累加起来,若该月是闰年中的月份并且该月还大于二月,再使总天数加1,否则,不加,既算出从定义年一月一日到输出年的该月一日的总天数。
2. 输出月份第一天为星期几的算法:使总天数除以7取余得几既为星期几,若是0,则为星期日。
3. 算出输出月份第一天为星期几的算法:算出输出月份第一天为星期几后,把该日期以前的位置用空格补上,并总该日起一次输出天数直到月底,该月中的天数加上该月一日为星期几的数字再除以7得0换行,即可完整的输出该月的日历。
4. 查询年份必须为四位有效数字,否则不予显示。
5.显示系统时间。
6.流程图流程图5.系统实现5.1 开发环境myeclipse-8.5.0-win325.2 关键技术(1)界面的绘制与显示public class wannianli extends JFrame implements ActionListener, MouseListener{private Calendar cld = Calendar.getInstance();private String [] astr = {"星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日"};private DefaultTableModel 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 JButton 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());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 JButton("删除日志");背景颜色,字体的显示table.setGridColor(Color.GRAY); //星期之间的网格线是灰色的table.setColumnSelectionAllowed(true);table.setSelectionBackground(Color.BLACK);//当选定某一天时这一天背景黑色table.setSelectionForeground(Color.GREEN);//选定的日期字体是绿色的table.setBackground(new Color(184,207,229));//日期显示表格颜色浅蓝色table.setFont(new Font("黑体",Font.BOLD,24));//日期数字字体格式table.setRowHeight(30);//表格的高度table.addMouseListener(this); //鼠标监听器(2)根据月份判断每个月的天数以及判断是否为闰年判断2月的天数public int getDaysOfMonth(int year, int Month) //显示所选月份的天数{if(Month == 1 || Month == 3 || Month == 5 || Month == 7 || Month == 8 || Month == 10 || Month == 12){return 31;}if(Month == 4 || Month == 6 || Month == 9 || Month == 11){return 30;}if(year%4 == 0 && year%100 != 0 || year%400 == 0)//闰年{return 29;}else{return 28;}(3)日志的添加与删除if(e.getSource() == bDel){int r = table.getSelectedRow();int c = table.getSelectedColumn();File filedel = new File(ld.getText() + ".txt");if(filedel.exists()){if(filedel.delete()){jta.setText("日志删除成功");}else{jta.setText("日志删除失败");}}else{jta.setText("没有找到日志文件");}}}(4)判断年份输入是否正确public void actionPerformed(ActionEvent e){if(e.getSource() == 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(jtfMonth.getText());}catch (NumberFormatException ex){JOptionPane.showMessageDialog(this, "请输入4位0-9的数字!", "年份有误", JOptionPane.ERROR_MESSAGE);return;}(5)显示系统时间lass Timer extends Thread//显示系统时间{private JLabel lt;private SimpleDateFormat fy= new SimpleDateFormat("yyyy.MM.dd G 'at' HH:mm:ss z");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 (InterruptedException ex){ex.printStackTrace();}}6.运行结果7.软件测试年份输入错误显示闰年2月份演示以及日志保存8.总结对于本程序的设计,首先考虑其功能有哪些,需要显示什么,如何进行窗体构建布局,需要用哪些知识点,如相关的类和对象等。