java万年历程序代码

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

package pack;

import javax.swing.*;

import java.awt.*;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.util.Calendar;

import java.util.Date;

public class rili extends JFrame implements ActionListener { JButton b_today, b_query;

JLabel lb_Year, lb_Month;

JButton b_week[] = new JButton[7];

JButton b_day[][] = new JButton[6][7];

Container thisContainer;

JPanel pUp;

JPanel pCenter;

JPanel pCenter_week, pCenter_day;

JComboBox year, month;

public void init() {

b_today = new JButton("Today");

b_query = new JButton("Query");

setTitle("日历");

lb_Year = new JLabel("Year");

lb_Month = new JLabel("Month");

year = new JComboBox();

month = new JComboBox();

setDate();

pUp = new JPanel();

pUp.add(lb_Year);

pUp.add(year);

pUp.add(lb_Month);

pUp.add(month);

pUp.add(b_today);

pUp.add(b_query);

b_today.addActionListener(this);

b_query.addActionListener(this);

pCenter = new JPanel();

pCenter_week = new JPanel();

b_week[0] = new JButton("星期日");

b_week[1] = new JButton("星期一");

b_week[2] = new JButton("星期二");

b_week[3] = new JButton("星期三");

b_week[4] = new JButton("星期四");

b_week[5] = new JButton("星期五");

b_week[6] = new JButton("星期六");

b_week[0].setSize(400, 200);

b_week[1].setSize(400, 200);

b_week[2].setSize(400, 200);

b_week[3].setSize(400, 200);

b_week[4].setSize(400, 200);

b_week[5].setSize(400, 200);

b_week[6].setSize(400, 200);

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

b_week[i].setEnabled(false);

pCenter_week.add(b_week[i]);

}

pCenter_day = new JPanel();

for (int cols = 0; cols < 6; cols++) {

for (int rows = 0; rows < 7; rows++) {

b_day[cols][rows] = new JButton("");

b_day[cols][rows].setSize(400, 200);

this.pCenter_day.add(b_day[cols][rows]);

}

}

pCenter_day.setLayout(new GridLayout(6, 7));

setDay(Integer.parseInt(this.year.getSelectedItem().toString()),

Integer.parseInt(this.month.getSelectedItem().toString()));

// setDay(2011,2);

pCenter.setLayout(new BorderLayout());

pCenter.add(pCenter_week, "North");

pCenter.add(pCenter_day, "Center");

thisContainer = this.getContentPane();

thisContainer.setLayout(new BorderLayout());

thisContainer.add(pUp, "North");

thisContainer.add(pCenter, "Center");

this.setVisible(true);

this.setResizable(false);

this.pack();

}

public void setDate() {

int year, month, day, week;

Calendar cal = Calendar.getInstance();

year = cal.get(Calendar.YEAR);

month = cal.get(Calendar.MONTH);

相关文档
最新文档