南昌大学实验报告格式

南昌大学实验报告格式
南昌大学实验报告格式

南昌大学实验报告

学生姓名:白飞龙学号:8001709001 专业班级:信安091班实验类型:□验证□综合□设计□创新实验日期:实验成绩:

(以下主要内容由学生完成)

一、实验项目名称

二、实验目的

三、实验基本原理

四、主要仪器设备及耗材

五、实验步骤

六、实验数据及处理结果

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import java.util.*;

public class calendar

{

//main主函数

public static void main(String[] args)

{

CalenderTrain window = new CalenderTrain();

}

}

class CalenderTrain extends JFrame implements ActionListener {

//月份下拉列表框

JComboBox Month = new JComboBox();

//年份下拉列表框

JComboBox Y ear = new JComboBox();

Label Y ear_l = new Label("Year");

Label Month_l = new Label("Month");

JButton[] button_day = new JButton[49];

Button button_ok = new Button("Confirm");

//button_ok.setBackground(Color.blue);

Button button_exit = new Button("Exit");

//button_exit.setBackground(Color.blue);

//Button_ok.setSize(20,5);

Button button_today = new Button("ShowToday");

//button_today.setBackground(Color.blue);

boolean signal = false;

//存放年份

String year_int = null;

//存放月份

int month_int;

//放置下拉列表框

JPanel pane1 = new JPanel();

//放置日期面板

JPanel pane2 = new JPanel();

//放置查询按钮与今天按钮

JPanel pane3 = new JPanel();

JPanel pane_parent = new JPanel();

Date now_date = new Date();

int now_year = now_date.getY ear() + 1900;

int now_month = now_date.getMonth();

//定义方法绘制面板

public CalenderTrain()

{

super("日历");

setDefaultCloseOperation(DISPOSE_ON_CLOSE); addWindowListener(

new WindowAdapter()

{

public void windowClose(WindowEvent e)

{

System.out.print("CLOSING THE WIN");

System.exit(0);

}

});

setResizable(true);

//设定年月

for (int i = now_year - 2010;i <= now_year + 2010; i++) {

//添加年份选项Item

Y ear.addItem(i + "");

}

//在月份下拉列表上添加年份选项Item

for (int i = 1; i < 13; i++) {

Month.addItem(i + "");

}

//窗口初始显示时间

//设定年份下拉列表为当前年份

Y ear.setSelectedIndex(now_year);

pane1.add(Y ear);

pane1.add(Y ear_l);

//设定月份下拉列表为当前月份

Month.setSelectedIndex(now_month);

pane1.add(Month);

pane1.add(Month_l);

pane1.add(button_ok);

pane3.add(button_today);

pane3.add(button_exit);

button_ok.addActionListener(this);

button_exit.addActionListener(this);

button_today.addActionListener(this);

//初始化日期按钮并绘制

//采用GDL网格布局,七行七列

pane2.setLayout(new GridLayout(7, 7, 10, 10));

for (int i = 0; i < 49; i++)

{

//初始化按钮

button_day[i] = new JButton(" ");

//添加天数按钮

pane2.add(button_day[i]);

}

this.setDay();

//调用setDay()方法

//设定布局管理器,将两个面板添到一起pane_parent.setLayout(new BorderLayout()); setContentPane(pane2);

setContentPane(pane1);

pane_parent.add(pane2, BorderLayout.CENTER); pane_parent.add(pane1, BorderLayout.NORTH); pane_parent.add(pane3, BorderLayout.SOUTH); setContentPane(pane_parent);

pack();

show();

}

void setDay()

{

if (signal)

{

//当前年月

year_int = now_year+ "" ;

month_int = now_month;

else

{

//自己选择的年月

year_int = Y ear.getSelectedItem().toString();

month_int = Month.getSelectedIndex();

}

//注意:用Integer类强制将string型转为Int型

int year_sel = Integer.parseInt(year_int) - 1900;

//构造一个日期

Date dt = new Date(year_sel, month_int, 1);

//创建一个Calendar实例

GregorianCalendar cal = new GregorianCalendar();

cal.setTime(dt);

String week[] = { "Sun日", "Mon一", "Tue二", "Wed三", "Thu四", "Fri五", "Sat六" }; int day = 0;

int day_week = 0;

//将星期添加到网格布局前7个按钮中

for (int i = 0; i < 7; i++)

{

button_day[i].setText(week[i]);

}

//判断选定月的天数

if (

month_int == 0

|| month_int == 2

|| month_int == 4

|| month_int == 6

|| month_int == 7

|| month_int == 9

|| month_int == 11)

{

day = 31;

}

else if (

month_int == 3

|| month_int == 5

|| month_int == 8

|| month_int == 10)

{

day = 30;

else

{

if (cal.isLeapY ear(year_sel))

{ day = 29; }

else { day = 28; }

}

// 注意:加7是因为前7个按钮已被添入实例day_week = 7 + dt.getDay();

int count = 1;

for (int i = day_week; i

if (i == day_week + now_date.getDate()-1)

{

button_day[i].setForeground(Color.red);

button_day[i].setText(count + "");

}

else

{

button_day[i].setForeground(Color.black);

button_day[i].setText(count + "");

}

}

//对于没有日期数值显示的按钮进行初始化

if (day_week == 1)

{

for (int i=day; i<49;i++)

{

button_day[i].setText("*");

}

}

else

{

//第一天前面的按钮置空

for (int i = 7; i < day_week; i++)

{

button_day[i].setForeground(Color.green);

button_day[i].setText("*");

}

//最后一天后面的按钮置空

for (int i = day_week + day; i < 49; i++)

{

button_day[i].setForeground(Color.green);

button_day[i].setText("*");

}

}

}

//内部函数

public void actionPerformed(ActionEvent e)

{

if (e.getSource() == button_ok)

{

signal= false;

this.setDay();

}

else if (e.getSource() == button_today)

{

signal= true;

Y ear.setSelectedIndex(now_year);

Month.setSelectedIndex(now_month);

this.setDay();

}

else if(e.getSource()==button_exit)

{

System.exit(0);

}

}

}

七、思考讨论题或体会或对改进实验的建议

八、参考资料

相关主题
相关文档
最新文档