java写万年历的代码Word 文档 (2)_第1页
java写万年历的代码Word 文档 (2)_第2页
java写万年历的代码Word 文档 (2)_第3页
java写万年历的代码Word 文档 (2)_第4页
java写万年历的代码Word 文档 (2)_第5页
已阅读5页,还剩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 SUN, MON, TUE, WED, THU, FRI, SAT ; private String stringWeekCn = new String 星期天, 星期一, 星期二, 星期三, 星期四, 星期五, 星期六 ; private String stringMonth = new String Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sept, Oct, Nov, Dec ; private String strSysTime = new String6; / 存储当前日期信息 private String strSysNowTime = new String6; / 存储运行时日期信息 private JButton buttonDay = new JButton42; private JButton buttonWeek = new JButton7; 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(, Font.PLAIN, 14); for (int y = 1900; y 2101; y+) comboYear.addItem( + new Integer(y).toString(); getContentPane().add(comboYear); comboYear.addItemListener(this); final JLabel labelYear = new JLabel(); labelYear.setForeground(Color.BLUE); labelYear.setFont(new Font(新宋体, Font.PLAIN, 14); getContentPane().add(labelYear); labelYear.setText( 年); comboMonth.setForeground(new Color(0, 0, 255); comboMonth.setFont(new Font(, Font.PLAIN, 14); for (int m = 1; m 13; m+) comboMonth.addItem( + new Integer(m).toString(); getContentPane().add(comboMonth); comboMonth.addItemListener(this); getContentPane().add(labelMonth); labelMonth.setForeground(Color.BLUE); labelMonth.setFont(new Font(新宋体, Font.PLAIN, 14); labelMonth.setText( 月); getContentPane().add(buttonLastMonth); buttonLastMonth.setForeground(Color.BLUE); buttonLastMonth.setFont(new Font(新宋体, Font.PLAIN, 14); buttonLastMonth.setText(上月); buttonLastMonth.addActionListener(this); getContentPane().add(buttonToday); buttonToday.setForeground(Color.BLUE); buttonToday.setFont(new Font(新宋体, Font.PLAIN, 14); buttonToday.setText(今天); buttonToday.addActionListener(this); getContentPane().add(buttonNextMonth); buttonNextMonth.setForeground(Color.BLUE); buttonNextMonth.setFont(new Font(新宋体, Font.PLAIN, 14); buttonNextMonth.setText(下月); buttonNextMonth.addActionListener(this); for (int i = 0; i 7; i+) buttonWeeki = new JButton(); if (i = 0 | i = 6) buttonWeeki.setForeground(Color.RED); else buttonWeeki.setForeground(Color.BLUE); buttonWeeki.setFont(new Font(新宋体, Font.PLAIN, 12); buttonWeeki.setText(stringWeekCni); getContentPane().add(buttonWeeki); for (int i = 0; i 42; i+) buttonDayi = new JButton(); buttonDayi.setText(); getContentPane().add(buttonDayi); this.setResizable(false); getSysNowTimeInfo(); setNowDate(); setNowDate(); public void setSysDate(int year, int month) / 将日期设置为year年month月1日 gregorianCalendar.set(year, month, 1); public void actionPerformed(ActionEvent ae) if (ae.getSource() = buttonToday) setNowDate(); setNowDate(); else if (ae.getSource() = buttonLastMonth) setDate(-1); else setDate(1); public void itemStateChanged(ItemEvent arg0) setDate(0); public void getSysNowTimeInfo() / 得到程序运行时的时间信息并存储在字符串数组strSysNowTime中 date = gregorianCalendar.getTime(); strSysNowTime = (date + ).split( ); public void getSysTimeInfo() / 得到系统当前的时间信息并存储在字符串数组strSysTime中 date = gregorianCalendar.getTime(); strSysTime = (date + ).split( ); public int getNowMonth() int month = 0; for (int i = 0; i 12; i+) if (strSysNowTime1.equalsIgnoreCase(stringMonthi) month = i; break; return month; public int weekStrat(String strWeek) / 返回字符串strWeek与星期中的第几天匹配,SUN为第一天 int strat = 0; for (int i = 0; i 7; i+) if (strWeek.equalsIgnoreCase(stringWeeki) strat = i; break; return strat; public void setNowDate() / 将时间设置为程序运行时的时间 setSysTime(getNowYear(), getNowMonth(); getSysTimeInfo(); setDayNull(); getDay(getMonthDays(getNowYear(), getNowMonth() - 1), getMonthDays( getNowYear(), getNowMonth(), weekStrat(strSysTime0), getNowDay(); comboYear.setSelectedIndex(getNowYear() - 1900); comboMonth.setSelectedIndex(getNowMonth(); public void setDate(int move) / 将时间设置为选中的年月增加move个月之后的时间 setSysTime(getYear(), getMonth() + move); getSysTimeInfo(); setDayNull(); getDay(getMonthDays(getYear(), getMonth() + move - 1), getMonthDays( getYear(), getMonth() + move), weekStrat(strSysTime0), -1); if (move != 0) if (getMonth() = 0 & move 0) move = -11; comboYear.setSelectedIndex(getYear() - 1899); else comboYear.setSelectedIndex(getYear() - 1900); comboMonth.setSelectedIndex(getMonth() + move); public void setSysTime(int year, int month) gregorianCalendar.set(year, month, 1); public int getNowYear() return Integer.parseInt(strSysNowTime5); public int getNowDay() return Integer.parseInt(strSysNowTime2); public int getYear() return comboYear.getSelectedIndex() + 1900; public int getMonth() return comboMonth.getSelectedIndex(); public void setDayNull() for (int d = 0; d 42; d+) buttonDayd.setText(); public void getDay(int lastMonDays, int monthDays, int startWeek, int day) / 设置日期颜色并打印 for (int d = 0; d startWeek + 1; d+) buttonDayd.setForeground(Color.GRAY); buttonDayd.setText(lastMonDays

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论