万年历Java课程设计.docx
- 文档编号:13055430
- 上传时间:2023-06-10
- 格式:DOCX
- 页数:31
- 大小:268.88KB
万年历Java课程设计.docx
《万年历Java课程设计.docx》由会员分享,可在线阅读,更多相关《万年历Java课程设计.docx(31页珍藏版)》请在冰点文库上搜索。
万年历Java课程设计
课程设计说明书NO.1
万年历程序设计
1、课程设计的目的
这学期我们学习了Java语言,Java语言是面向对象的开发方法是当今世界最流行的开发方法,是当今流行的网络编程语言。
它具有面向对象、跨平台、分布应用等特点。
它不仅具有更贴近自然的语义,而且有利于软件的维护和继承。
很多程序开发人员得第一选择。
为了进一步巩固课堂上所学到的知识,深刻把握Java语言的重要概念及其面向对象的特性,锻炼学生熟练的应用面向对象的思想和设计方法解决实际问题的能力,开设了Java程序设计课程设计。
让学生自己动手动脑,将书本上得知识运用到实践当中去,使知识能更好得融会贯通。
为了达到这个目的,我们需要自己动手做一个Java的课程设计,在这个课程设计里我们需要根据我们手中现有得软件与知识基础,独立得将它完成,只有这样,我们才能把理论变成实践,将知识真正得做到学以致用。
这次课程设计我主要研究了利用已学的Java知识编辑一个电子万年历。
通过此次课程设计,来巩固所学Java语言基本知识,增进Java语言编辑基本功,掌握JDK、JCreator等开发工具的运用,拓宽常用类库的应用。
并通过自己动手,自主得学习,对Java这门课程有更深得了解与认识。
2、设计方案论证
2.1课程设计的基本要求
万年历有很多作用,顾名思义它是一种很方便得计时计年工具,随着科技得发展,我们已经可以通过计算机制作出精美的万年历,通过计算机制作得万年历不但外观美观,而且功能强大。
通过万年历,我们可以实现很多功能,随意看某年得年份,某年得月份,随意调整某年得某天,并将其显示出来,而且有判断闰年闰月得功能,十分方便。
除此之外,万年历还具有记事本功能,通过记事本功能可以备忘一些事情,备忘得事情可以随意添加在万年历得任意年月日里,如果记录得容已经不再需要,还可以任意的将记录得容进行删除,在删除得时候还会提示,是否确定删除,如果是,则程序会将它删除,如果不是,则系统不会将它删除。
2.2方案论证
阳大学
课程设计说明书NO.2
2.2.1方法
表1方法表
方法名
功能
备注(须输入的参数)
calendar
初始化各种数据
intyear,intmonth,intday
SwitchMonth
选择月份
intmonth
PrintMonth
显示月份
intyear,intmonth,intday
PrintMonthBody
月份体
intstartday,intdayinmonth
IsLeapYear
GetStartDay
GetTotalNumOfDays
GetNumOfDaysInMonth
WriteRecord
ReadRecord
DeleteFile
AboutActionListenerWay
actionPerformed(ActionEvent)
mousePressed
mouseClicked
mouseReleased
mouseEntered
mouseExited
SaveLog
Main
判断是否为闰年
得到开始的天
得到总天数
得到当月的天数
写日记
看日记
删除日记
监听路径
时间表现
鼠标点击
鼠标点击生
点击释放
鼠标进入
鼠标推出
保存日期
主函数
intyear
intyear,intmonth
intyear,intmonth
intyear,intmonth
唯一的主函数
阳大学
课程设计说明书NO.3
2.2.2程序流程框图
图1主程序流程图
图2计算阳历程序流程图
阳大学
课程设计说明书NO.4
图3时间调整程序流程图
阳大学
课程设计说明书NO.5
2.3程序说明
2.3.1成员变量见表2变量表
表2变量表
成员变量描述
变量类型
名称
年、月、日
int
Year、month、day
下一年,下一月
Int
Yearafterquery,monthafterquey
开始的时间
Int
startday
选择月,天
String
SwitchMonth,key,day
改变年
改变月
前一月,前一年
判断是否改变
左、又面板
年、月
左上角信息标签
显示月、年标签
空格标签
右上部时间标签
星期标签数组
月份下拉列表
时间确定按钮
保存、删除按钮
前、下一月按钮
文本区
星期字符串数组
显示天的文本区
输入年的文本区
Int
Int
Int
boolean
JPanel
JLabel
JLabel
JLabel
JLabel
JLabel
JLabel[]
JComboBox
JButton
JButton
JButton
JTextArea
String
JTextField
JTextField
Changeyearmessage
changemonthmessage
priormonth,prioryear
ischange,ischange_priornext
LeftPane,RightPane
YearLabel,MonthLabel
Ask
ShowDate
Blank
NorthMonthDayYear
TopBarTitle[]
MonthCombobox
Query
SouthSave,SouthDelete
PriorMonth,NextMonth
CenterText
week[]
ShowDays[]
YearText
阳大学
课程设计说明书NO.6
2.4程序源代码
importjava.awt.*;
importjava.awt.event.*;
importjavax.swing.*;
importjavax.swing.event.*;
importjavax.swing.border.*;
importjava.util.Calendar;
importjava.util.*;
importjava.io.*;
importjava.io.IOException;
publicclasscalendarextendsJFrame
implementsActionListener,MouseListener
{
intyear,month,day;
intyearafterquery,monthafterquery;
intstartday;
StringSwitchMonth;
Stringkey;
intchangeyearmessage;
intchangemonthmessage;
intpriormonth;
intprioryear;
booleanischange=false;
booleanischange_priornext=false;
privateJPanelLeftPane,RightPane;
//Leftsub
privateJLabelYearLabel;
privateJLabelMonthLabel;
privateJComboBoxMonthCombobox;
privateJTextFieldShowDays[]=newJTextField[42];
privateJTextFieldYearText;
privateJLabelAsk;
privateJLabelShowDate;
privateJLabelBlank;
privateJLabelTopBarTitle[]=newJLabel[7];
privateJButtonToToday;
privateJButtonQuery;
private
Stringweek[]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
//rightsub
privateJLabelNorthMonthDayYear;
阳大学
课程设计说明书NO.7
privateJTextAreaCenterText;
privateJButtonSouthSave,SouthDelete;
privateJButtonPriorMonth;
privateJButtonNextMonth;
publiccalendar(intyear,intmonth,intday)
{
setTitle("MyCalendar&Textbook");
//thelayoutaboutleftofjpane
LeftPane=newJPanel();
JPanelLeftCenter=newJPanel();
JPanelLeftNorth=newJPanel();
//JPanelLeftSouth=newJPanel();
LeftPane.setLayout(newBorderLayout());
LeftPane.add(LeftNorth,BorderLayout.NORTH);
LeftPane.add(LeftCenter,BorderLayout.CENTER);
LeftPane.add(ToToday=newJButton("Gototoday",newImageIcon("../images/Handle.gif")),BorderLayout.SOUTH);
ToToday.setBackground(Color.cyan);
ToToday.addActionListener(this);
LeftPane.validate();
//thelayoutofLeftPane
//LeftPane_North
LeftNorth.setLayout(newGridLayout(3,1,0,-2));
LeftNorth.add(Ask=newJLabel("Pleseinputtheinformationswhichyouwantquery:
"));
JPanelNorth=newJPanel(newFlowLayout(0,8,0));
LeftNorth.add(North);
North.add(YearLabel=newJLabel("Year:
"));
North.add(YearText=newJTextField(4));
YearText.setBackground(Color.getHSBColor(30,20,50));
YearText.setForeground(Color.blue);
YearText.setFont(newFont("TimesRoman",Font.BOLD,17));
YearText.addActionListener(this);
YearText.setFocusable(true);
North.add(Blank=newJLabel(""));
North.add(MonthLabel=newJLabel("Month:
"));
North.add(MonthCombobox=newJComboBox());
//addmonthtomonthcombobox
for(inti=1;i<=12;i++)
{
MonthCombobox.addItem(newInteger(i));
}
阳大学
课程设计说明书NO.8
//Switchthemonth
MonthCombobox.setForeground(Color.blue);
MonthCombobox.setFont(newFont("TimesRoman",Font.BOLD,12));
North.add(Blank=newJLabel(""));
North.add(Query=newJButton("Query"));
Query.setForeground(Color.blue);
Query.addActionListener(this);
JPanelNorth2=newJPanel(newFlowLayout());
LeftNorth.add(North2);
North2.add(PriorMonth=newJButton(newImageIcon("../images/prior.gif")));
PriorMonth.addActionListener(this);
PriorMonth.setActionCommand("prior");
priormonth=month;
prioryear=year;
SwitchMonth(month);
North2.add(ShowDate=newJLabel(SwitchMonth+""+","+""+String.valueOf(year),SwingConstants.CENTER));
ShowDate.setForeground(Color.blue);
ShowDate.setFont(newFont("TimesRoman",Font.BOLD,14));
North2.add(NextMonth=newJButton(newImageIcon("../images/next.gif")));
NextMonth.addActionListener(this);
NextMonth.setActionCommand("next");
//LeftPane_Center
LeftCenter.setLayout(newGridLayout(7,7));
//printtitle
for(inti=0;i<7;i++)
{
TopBarTitle[i]=newJLabel();
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]);
}
//printscreenandaddlistener
for(inti=0;i<42;i++)
{
ShowDays[i]=newJTextField();
ShowDays[i].addMouseListener(this);
ShowDays[i].setEditable(false);
阳大学
课程设计说明书NO.9
LeftCenter.add(ShowDays[i]);
}
//printthebodyofmonth
PrintMonth(year,month,day);
//thelayoutaboutrightofjpane
RightPane=newJPanel(newBorderLayout());
JPanelRightCenter=newJPanel();
JPanelRightNorth=newJPanel();
JPanelRightSouth=newJPanel(newFlowLayout());
RightPane.add(RightNorth,BorderLayout.NORTH);
RightPane.add(RightCenter,BorderLayout.CENTER);
RightPane.add(RightSouth,BorderLayout.SOUTH);
RightNorth.add(NorthMonthDayYear=newJLabel(">>"+year+","+SwitchMonth+","+day+"<<"));
key=year+"_"+SwitchMonth+"_"+day;
NorthMonthDayYear.setForeground(Color.blue);
NorthMonthDayYear.setFont(newFont("TimesRoman",Font.BOLD,17));
RightCenter.add(CenterText=newJTextArea("pleasewritetoday'sthings."));
CenterText.setLineWrap(true);
CenterText.setSelectedTextColor(Color.blue);
//CenterText.addActionListener(this);
RightSouth.add(SouthSave=newJButton("Save"));
SouthSave.setBackground(Color.cyan);
SouthSave.addActionListener(this);
SouthSave.setActionCommand("Save");
RightSouth.add(SouthDelete=newJButton("Delete"));
SouthDelete.setBackground(Color.cyan);
SouthDelete.addActionListener(this);
SouthDelete.setActionCommand("Delete");
this.year=year;
this.month=month;
this.day=day;
///addcontainertoputLeftPaneandRightPane
Containercon=getContentPane();
JSplitPanesplit=newJSplitPane(JSplitPane.HORIZONTAL_SPLIT,RightPane,LeftPane);//gaibian
con.add(split,BorderLayout.CENTER);
con.validate();
//addCenterPanetonotepad
//CenterPaneinitialize
setFont(newFont("TimesNewRoman",Font.PLAIN,12));
阳大学
课程设计说明书NO.10
JScrollPanescrollpane=newJScrollPane(CenterText);
scrollpane.setPreferredSize(newDimension(220,250));
RightCenter.add(scrollpane);
//initrandomaccessfile
}
//switchthemonthinenglish
publicvoidSwitchMonth(intmonth)
{
switch(month)
{
case1:
SwitchMonth="Jan";break;
case2:
SwitchMonth="Feb";break;
case3:
SwitchMonth="Mar";break;
case4:
SwitchMonth="Apr";break;
case5:
SwitchMonth="May";break;
case6:
SwitchMonth="Jun";break;
case7:
SwitchMonth="Jul";break;
case8:
SwitchMonth="Aug";break;
case9:
SwitchMonth="Sep";break;
case10:
SwitchMonth="Qct";break;
case11:
SwitchMonth="Nov";break;
case12:
SwitchMonth="Dec";break;
}
}
//printthebodyofthemonth
publicvoidPrintMonth(intyear,intmonth,intday)
{
//Getstartdayoftheweekforthefirstdateinthemonth
intstartday=GetStartDay(year,month);
阳大学
课程设计说明书NO.11
//Getnumberofdaysinthemonth
intdayinmonth=GetNumOfDaysInMonth(year,month);
//Printheader
//PrintTitleAndScreen();
//Printbody
PrintMonthBody(startday,dayinmonth,day);
}
//PrintMonth(intyear,intmonth,intday)'sburden
publicvoidPrintMonth(intyear,intmonth)
{
//Getstartdayoftheweekforthefirstdateinthemonth
intstartday=GetStartDay(year,month);
//Getnumberofdaysinthemonth
intdayinmonth=GetNumOfDaysInMonth(year,month);
//Printheader
//Printbody
PrintMonthBody(startday,dayinmonth);
}
//PrintMonthBody(intstartday,intdayinmonth,intday)'sburden
publicvoidPrintMonthBody(intstartday,intdayinmonth)
{
for(inti=startday,n=1;i { S
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 万年历 Java 课程设计
![提示](https://static.bingdoc.com/images/bang_tan.gif)