万年历java

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

packageclock;/***//***MainFrame.java*Summary万年历主类*Createdon*@author*remark*/importjava.awt.BorderLayout;importjava.awt.Color;importjava.awt.GridLayout;importjava.awt.Toolkit;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.sql.Date;importjava.util.Calendar;importjavax.swing.JComboBox;importjavax.swing.JFrame;importjavax.swing.JLabel;importjavax.swing.JPanel;classMainFrameextendsJFrame{/***//****/privatestaticfinallongserialVersionUID=1L;JPanelpanel=newJPanel(newBorderLayout());JPanelpanel1=newJPanel();JPanelpanel2=newJPanel(newGridLayout(7,7));JPanelpanel3=newJPanel();JLabel[]label=newJLabel[49];JLabely_label=newJLabel(年份);JLabelm_label=newJLabel(月份);JComboBoxcom1=newJComboBox();JComboBoxcom2=newJComboBox();intre_year,re_month;intx_size,y_size;Stringyear_num;Calendarnow=Calendar.getInstance();//实例化CalendarMainFrame(){super(万年历);setSize(300,350);x_size=(int)(Toolkit.getDefaultToolkit().getScreenSize().getWidth());y_size=(int)(Toolkit.getDefaultToolkit().getScreenSize().getHeight());setLocation((x_size-300)/2,(y_size-350)/2);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);panel1.add(y_label);panel1.add(com1);panel1.add(m_label);panel1.add(com2);for(inti=0;i49;i++){label[i]=newJLabel(,JLabel.CENTER);//将显示的字符设置为居中panel2.add(label[i]);}panel3.add(newClock(this));panel.add(panel1,BorderLayout.NORTH);panel.add(panel2,BorderLayout.CENTER);panel.add(panel3,BorderLayout.SOUTH);panel.setBackground(Color.white);panel1.setBackground(Color.white);panel2.setBackground(Color.white);panel3.setBackground(Color.white);Init();com1.addActionListener(newClockAction());com2.addActionListener(newClockAction());setContentPane(panel);setVisible(true);setResizable(false);}classClockActionimplementsActionListener{publicvoidactionPerformed(ActionEventarg0){intc_year,c_month,c_week;c_year=Integer.parseInt(com1.getSelectedItem().toString());//得到当前所选年份c_month=Integer.parseInt(com2.getSelectedItem().toString())-1;//得到当前月份,并减1,计算机中的月为0-11c_week=use(c_year,c_month);//调用函数use,得到星期几Resetday(c_week,c_year,c_month);//调用函数Resetday}}publicvoidInit(){intyear,month_num,first_day_num;Stringlog[]={日,一,二,三,四,五,六};for(inti=0;i7;i++){label[i].setText(log[i]);}for(inti=0;i49;i=i+7){label[i].setForeground(Color.red);//将星期日的日期设置为红色}for(inti=6;i49;i=i+7){label[i].setForeground(Color.green);//将星期六的日期设置为绿色}for(inti=1;i10000;i++){com1.addItem(+i);}for(inti=1;i13;i++){com2.addItem(+i);}month_num=(int)(now.get(Calendar.MONTH));//得到当前时间的月份year=(int)(now.get(Calendar.YEAR));//得到当前时间的年份com1.setSelectedIndex(year-1);//设置下拉列表显示为当前年com2.setSelectedIndex(month_num);//设置下拉列表显示为当前月first_day_num=use(year,month_num);Resetday(first_day_num,year,month_num);}publicintuse(intreyear,intremonth){intweek_num;now.set(reyear,remonth,1);//设置时间为所要查询的年月的第一天week_num=(int)(now.get(Calendar.DAY_OF_WEEK));//得到第一天的星期returnweek_num;}@SuppressWarnings(deprecation)publicvoidResetday(intweek_log,intyear_log,intmonth_log){intmonth_day_score;//存储月份的天数intcount;month_day_score=0;count=1;Datedate=newDate(year_log,month_log+1,1);//nowCalendarcal=Calendar.getInstance();cal.setTime(date);cal.add(Calendar.MONTH,-1);//前个月month_day_score=cal.getActualMaximum(Calendar.DAY_OF_MONTH);//最后一天for(inti=7;i49;i++){//初始化标签label[i].setText();}week_log=week_log+6;//将星期数加6,使显示正确month_day_score=month_day_score+week_log;for(inti=week_log;imonth_day_score;i++,count++){label[i].setText(count+);}}publicstaticvoidmain(String[]args){JFrame.setDefaultLookAndFeelDecorated(true);newMainFrame();}万年历二/***//***MainFrame.java*Summary万年历主类*Createdon*@author*remark*/importjava.awt.BorderLayout;importjava.awt.Color;importjava.awt.GridLayout;importjava.awt.Toolkit;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.sql.Date;importjava.util.Calendar;importjavax.swing.JComboBox;importjavax.swing.JFrame;importjavax.swing.JLabel;importjavax.swing.JPanel;classMainFrameextendsJFrame{/***//****/privatestaticfinallongserialVersionUID=1L;JPanelpanel=newJPanel(newBorderLayout());JPanelpanel1=newJPanel();JPanelpanel2=newJPanel(newGridLayout(7,7));JPanelpanel3=newJPanel();JLabel[]label=newJLabel[49];JLabely_label=newJLabel(年份);JLabelm_label=newJLabel(月份);JComboBoxcom1=newJComboBox();JComboBoxcom2=newJComboBox();intre_year,re_month;intx_size,y_size;Stringyear_num;Calendarnow=Calendar.getInstance();//实例化CalendarMainFrame(){super(万年历);setSize(300,350);x_size=(int)(Toolkit.getDefaultToolkit().getScreenSize().getWidth());y_size=(int)(Toolkit.getDefaultToolkit().getScreenSize().getHeight());setLocation((x_size-300)/2,(y_size-350)/2);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);panel1.add(y_label);panel1.add(com1);panel1.add(m_label);panel1.add(com2);for(inti=0;i49;i++){label[i]=newJLabel(,JLabel.CENTER);//将显示的字符设置为居中panel2.add(label[i]);}panel3.add(newClock(this));panel.add(panel1,BorderLayout.NORTH);panel.add(panel2,BorderLayout.CENTER);panel.add(panel3,BorderLayout.SOUTH);panel.setBackground(Color.white);panel1.setBackground(Color.white);panel2.setBackground(Color.white);panel3.setB

1 / 13
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功