Java课程设计-万年历Word格式.doc

上传人:wj 文档编号:3583142 上传时间:2023-05-02 格式:DOC 页数:15 大小:135KB
下载 相关 举报
Java课程设计-万年历Word格式.doc_第1页
第1页 / 共15页
Java课程设计-万年历Word格式.doc_第2页
第2页 / 共15页
Java课程设计-万年历Word格式.doc_第3页
第3页 / 共15页
Java课程设计-万年历Word格式.doc_第4页
第4页 / 共15页
Java课程设计-万年历Word格式.doc_第5页
第5页 / 共15页
Java课程设计-万年历Word格式.doc_第6页
第6页 / 共15页
Java课程设计-万年历Word格式.doc_第7页
第7页 / 共15页
Java课程设计-万年历Word格式.doc_第8页
第8页 / 共15页
Java课程设计-万年历Word格式.doc_第9页
第9页 / 共15页
Java课程设计-万年历Word格式.doc_第10页
第10页 / 共15页
Java课程设计-万年历Word格式.doc_第11页
第11页 / 共15页
Java课程设计-万年历Word格式.doc_第12页
第12页 / 共15页
Java课程设计-万年历Word格式.doc_第13页
第13页 / 共15页
Java课程设计-万年历Word格式.doc_第14页
第14页 / 共15页
Java课程设计-万年历Word格式.doc_第15页
第15页 / 共15页
亲,该文档总共15页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

Java课程设计-万年历Word格式.doc

《Java课程设计-万年历Word格式.doc》由会员分享,可在线阅读,更多相关《Java课程设计-万年历Word格式.doc(15页珍藏版)》请在冰点文库上搜索。

Java课程设计-万年历Word格式.doc

动手能力:

强□较强□一般□较差□

团队精神:

创新意识:

强□较强□一般□较差□

课程设计完成情况:

优秀□好□一般□较差□

课程设计报告完成情况:

优秀□好□一般□较差□

年月日

 

目 

1.课程设计目的 

..................................................................................................1 

2.需求分析...........................................................................................................1 

3.总体设计...........................................................................................................1 

4.详细设计...........................................................................................................1 

5.软件测试...........................................................................................................10

6.课程设计总结...................................................................................................11

一、课程设计目的

(1)熟练使用java语言编写程序,解决实际问题。

(2)初步掌握软件开发过程的问题分析、系统设计、程序编码、测试等基本方法和技能;

(3)学会自己调试程序的方法并掌握一定的技巧。

二、需求分析

本程序的要求为:

1.使用图形用户界面;

2.本程序能够实现日期与星期的查询。

三、总体设计 

(1)可以通过图形界面显示日历。

(2)能以月历形式显示日期与星期。

(3)支持用户自己输入年份,可以通过上一年,下一年等按钮来选择年份和月份。

四、详细设计 

1.总天数的算法:

首先用if语句判断定义年到输入年之间每一年是否为闰年,是闰年,该年的总天数为366,否则,为365。

2.输出月份第一天为星期几的算法:

使总天数除以7取余得几既为星期几,若是0,则为星期日。

3.算出输出月份第一天为星期几的算法:

算出输出月份第一天为星期几后,把该日期以前的位置用空格补上,并总该日起一次输出天数直到月底,该月中的天数加上该月一日为星期几的数字再除以7得0换行,即可完整的输出该月的日历。

4.查询年份必须为四位有效数字,否则不予显示。

程序源代码:

importjava.awt.BorderLayout;

importjava.awt.Color;

importjava.awt.FlowLayout;

importjava.awt.Font;

importjava.awt.GridLayout;

importjava.awt.event.ActionEvent;

importjava.awt.event.ActionListener;

importjava.awt.event.ItemEvent;

importjava.sql.Date;

importjava.text.DateFormat;

importjava.text.SimpleDateFormat;

importjava.util.Calendar;

importjava.awt.*;

importjava.awt.event.*;

importjava.text.*;

importjava.time.Clock;

importjava.util.*;

importjavax.swing.*;

importjavax.swing.table.*;

importjavax.swing.table.DefaultTableModel;

publicclasswannianliextendsJFrameimplementsActionListener{

privateCalendarcal=Calendar.getInstance();

privateString[]str={"

星期一"

"

星期二"

星期三"

星期四"

星期五"

星期六"

星期日"

};

privateDefaultTableModeldtm=newDefaultTableModel(null,str);

privateJTabletable=newJTable(dtm);

//装日期的表格

privateJScrollPanesp=newJScrollPane(table);

privateJButtonbLastYear=newJButton("

上一年"

);

privateJButtonbNextYear=newJButton("

下一年"

privateJButtonbLastMonth=newJButton("

上月"

privateJButtonbNextMonth=newJButton("

下月"

privateJTextFieldYear=newJTextField(4);

//jtfYear年份显示和输入文本

privateJLabeljla=newJLabel("

年"

privateJTextFieldmonth=newJTextField(4);

privateJLabeljla1=newJLabel("

月"

privateJTextFieldjtfMonth=newJTextField

(2);

//jtfMonth月份显示文本框

privateJComboBoxcomb;

privateJPanelp1=newJPanel();

//装入控制日期按钮的模块

privateJPanelp2=newJPanel();

privateJPanelp3=newJPanel(newGridLayout(2,1));

privateJPanelp4=newJPanel();

privateJPanelp5=newJPanel();

privateJLabell=newJLabel("

文本框中可直接键入要查找的年份,以提高查询效率"

privateJLabellt=newJLabel();

privateJLabelcom=newJLabel("

请选择月份:

"

privateintlastTime;

private

wannianli(){

super("

万年历"

//框架命名

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//窗口关闭函数

table.setGridColor(Color.GRAY);

//星期之间的网格线是灰色的

table.setColumnSelectionAllowed(true);

table.setSelectionBackground(Color.BLACK);

//当选定某一天时这一天背景黑色

table.setSelectionForeground(Color.GREEN);

//选定的日期字体是绿色的

table.setBackground(newColor(184,207,229));

//日期显示表格颜色浅蓝色

table.setFont(newFont("

黑体"

Font.BOLD,24));

//日期数字字体格式

table.setRowHeight(30);

//表格的高度

Year.addActionListener(this);

//可输入年份的文本框

//month.addActionListener(this);

//可输入年份的文本框//为各个按钮添加监听函数

bLastYear.addActionListener(this);

bNextYear.addActionListener(this);

bLastMonth.addActionListener(this);

bNextMonth.addActionListener(this);

//将按钮添加到

String[]str={"

1"

"

2"

3"

4"

5"

6"

7"

8"

9"

10"

11"

12"

comb=newJComboBox(str);

p1.add(bLastYear);

p1.add(Year);

//年份输入文本框

p1.add(jla);

p1.add(month);

//年份输入文本框

p1.add(jla1);

p1.add(bNextYear);

p1.add(bLastMonth);

p1.add(jtfMonth);

p1.add(bNextMonth);

p1.add(com);

p1.add(comb);

p2.setLayout(newFlowLayout());

p2.add(p4,BorderLayout.EAST);

p2.add(sp,BorderLayout.CENTER);

p2.add(p5,BorderLayout.WEST);

p3.add(l);

p3.add(lt);

this.add(p3,BorderLayout.SOUTH);

this.add(p2,BorderLayout.CENTER);

this.add(p1,BorderLayout.NORTH);

String[]strDate=DateFormat.getDateInstance().format(newjava.util.Date()).split("

-"

cal.set(Integer.parseInt(strDate[0]),Integer.parseInt(strDate[1])-1,0);

showCalendar(Integer.parseInt(strDate[0]),Integer.parseInt(strDate[1]),cal);

jtfMonth.setEditable(false);

//设置月份的文本框为不可编辑

Year.setText(strDate[0]);

month.setText(strDate[1]);

comb.setToolTipText(strDate[1]);

comb.addItemListener(newItemListener(){

publicvoiditemStateChanged(ItemEvente){

jtfMonth.setText((String)comb.getSelectedItem());

month.setText((String)comb.getSelectedItem());

intm,y;

try//控制输入的年份正确,异常控制

{

if(Year.getText().length()!

=4)

{thrownewNumberFormatException();

}

y=Integer.parseInt(Year.getText());

m=Integer.parseInt(jtfMonth.getText());

}

catch(NumberFormatExceptionex)

{

//JOptionPane.showMessageDialog(this,"

请输入4位0-9的数字!

年份有误"

JOptionPane.ERROR_MESSAGE);

return;

}

for(inti=0;

i<

lastTime+1;

i++)

{

dtm.removeRow(0);

}

cal.set(y,m-1,0);

showCalendar(y,m,cal);

}

});

jtfMonth.setText("

month.setText("

this.setBounds(200,200,700,320);

this.setResizable(false);

this.setVisible(true);

}

publicstaticvoidmain(String[]args)

{

newwannianli();

publicvoidshowCalendar(intlocalYear,intlocalMonth,Calendarcld){

intDays=getDaysOfMonth(localYear,localMonth)+cld.get(Calendar.DAY_OF_WEEK)-2;

Object[]ai=newObject[7];

lastTime=0;

for(inti=cld.get(Calendar.DAY_OF_WEEK)-1;

=Days;

i++)

{

ai[i%7]=String.valueOf(i-(cld.get(Calendar.DAY_OF_WEEK)-2));

if(i%7==6)

{

dtm.addRow(ai);

ai=newObject[7];

lastTime++;

}

}

dtm.addRow(ai);

}

publicintgetDaysOfMonth(intyear,intMonth)//显示所选月份的天数

{

if(Month==1||Month==3||Month==5||Month==7||Month==8||Month==10||Month==12)

{

return31;

}

if(Month==4||Month==6||Month==9||Month==11)

{

return30;

}

if(year%4==0&

&

year%100!

=0||year%400==0)//闰年

{

return29;

}

else

{

return28;

}

}

publicvoidactionPerformed(ActionEvente)

if(e.getSource()==Year||e.getSource()==bLastYear||e.getSource()==bNextYear||e.getSource()==bLastMonth||e.getSource()==bNextMonth)

{

intm,y;

try//控制输入的年份正确,异常控制

{

if(Year.getText().length()!

{thrownewNumberFormatException();

}

y=Integer.parseInt(Year.getText());

m=Integer.parseInt(jtfMonth.getText());

}catch(NumberFormatExceptionex)

{

JOptionPane.showMessageDialog(this,"

return;

}

for(inti=0;

{

dtm.removeRow(0);

}

if(e.getSource()==bLastYear)

{

Year.setText(String.valueOf(--y));

}

if(e.getSource()==bNextYear)

{

Year.setText(String.valueOf(++y));

}

if(e.getSource()==bLa

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 农林牧渔 > 水产渔业

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2