java写万年历的代码Word 文档 (2)

import java.awt.Color; import java.awt.Font;

import java.awt.GridLayout;

import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.util.Date;

import java.util.GregorianCalendar; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JLabel;

public class Calender2 extends JFrame implements ActionListener, ItemListener { /**

* 实现简单的日历功能 *

* @author Jadie version 1.0 2007/12/29 * */

private static final long serialVersionUID = 1L;

public static void main(String args[]) { try {

Calender2 frame = new Calender2(); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } }

private Date date = new Date();

private GregorianCalendar gregorianCalendar = new GregorianCalendar();

private String[] stringWeek = new String[] { \ \

private String[] stringWeekCn = new String[] { \星期天\星期一\星期二\星期三\ \星期四\星期五\星期六\

private String[] stringMonth = new String[] { \ \ private String[] strSysTime = new String[6]; // 存储当前日期信息

private String[] strSysNowTime = new String[6];

// 存储运行时日期信息

private JButton[] buttonDay = new JButton[42]; private JButton[] buttonWeek = new JButton[7]; private JLabel labelMonth = new JLabel(); private JButton buttonToday = new JButton();

private JButton buttonLastMonth = new JButton(); private JButton buttonNextMonth = new JButton(); private JComboBox comboYear = new JComboBox(); private JComboBox comboMonth = new JComboBox(); public Calender2() {

super(\万年历---156制作\

getContentPane().setLayout(new GridLayout(8, 7, 3, 5)); setBounds(250, 200, 530, 360);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

comboYear.setForeground(new Color(0, 0, 255)); comboYear.setFont(new Font(\ for (int y = 1900; y < 2101; y++) {

comboYear.addItem(\ \ }

getContentPane().add(comboYear); comboYear.addItemListener(this);

final JLabel labelYear = new JLabel(); labelYear.setForeground(Color.BLUE);

labelYear.setFont(new Font(\新宋体\ getContentPane().add(labelYear); labelYear.setText(\ 年\

comboMonth.setForeground(new Color(0, 0, 255)); comboMonth.setFont(new Font(\ for (int m = 1; m < 13; m++) {

comboMonth.addItem(\ \ }

getContentPane().add(comboMonth); comboMonth.addItemListener(this);

getContentPane().add(labelMonth); labelMonth.setForeground(Color.BLUE);

labelMonth.setFont(new Font(\新宋体\ labelMonth.setText(\ 月\

getContentPane().add(buttonLastMonth);

buttonLastMonth.setForeground(Color.BLUE);

buttonLastMonth.setFont(new Font(\新宋体\ buttonLastMonth.setText(\上月\

buttonLastMonth.addActionListener(this);

getContentPane().add(buttonToday); buttonToday.setForeground(Color.BLUE);

buttonToday.setFont(new Font(\新宋体\ buttonToday.setText(\今天\

buttonToday.addActionListener(this);

getContentPane().add(buttonNextMonth); buttonNextMonth.setForeground(Color.BLUE);

buttonNextMonth.setFont(new Font(\新宋体\ buttonNextMonth.setText(\下月\

buttonNextMonth.addActionListener(this);

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

buttonWeek[i] = new JButton(); if (i == 0 || i == 6) {

buttonWeek[i].setForeground(Color.RED); } else {

buttonWeek[i].setForeground(Color.BLUE); }

buttonWeek[i].setFont(new Font(\新宋体\ buttonWeek[i].setText(stringWeekCn[i]); getContentPane().add(buttonWeek[i]); }

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

buttonDay[i] = new JButton(); buttonDay[i].setText(\

getContentPane().add(buttonDay[i]); }

this.setResizable(false); getSysNowTimeInfo(); setNowDate(); setNowDate(); }

public void setSysDate(int year, int month) { // 将日期设置为year年month月1日 gregorianCalendar.set(year, month, 1); }

联系客服:779662525#qq.com(#替换为@) 苏ICP备20003344号-4