1、import java.awt.*;import java.awt.event.*;import java.util.*;public class CalenderCreator extends FrameButton days=new Button49;Choice Month=new Choice();Choice Year=new Choice();Label lmonth=new Label(MONTH);Label lyear=new Label(Year);Label ltext=new Label(YEAR UPTO:);Panel p1,p2;GregorianCalendar
2、 gc=new GregorianCalendar();int totdays;TextField textfield=new TextField(2);public CalenderCreator()setTitle(日历);setSize(400,400);setResizable(false);setLocation(50,50);p1=new Panel(new FlowLayout();p2=new Panel(new GridLayout(7,7,10,10);p1.setBackground(Color.pink);p2.setBackground(Color.white);ad
3、d(p1,BorderLayout.NORTH);add(p2);p1.add(ltext);p1.add(textfield);p1.add(lmonth);p1.add(Month);Month.add(一月);Month.add(二月);Month.add(三月);Month.add(四月);Month.add(五月);Month.add(六月);Month.add(七月);Month.add(八月);Month.add(九月);Month.add(十月);Month.add(十一);Month.add(十二);Month.addItemListener(new myLis(this);
4、/ int i1=myAction.newyear; / System.out.println(iiiiiiiiii is :+i1); /textfield.addActionListener(new myAction(this); /p1.add(lyear);p1.add(Year);Year.add(2012);Year.add(2013);Year.add(2014);Year.add(2015);Year.add(2016);Year.add(2017);Year.addItemListener(new myLis(this);for(int i=0;i49;i+)daysi=ne
5、w Button();for(int c=0;c49;c+)p2.add(daysc);setVisible(true);void setYear(String mynewyear)int h=Integer.parseInt(mynewyear);for(int adder=2013;adder0)int blank= myday;for( ;blank0;blank-,count+)dayscount.setLabel();for(int i=1;i=mytotdays; i+,count+)dayscount.setLabel(+i);for(int j = 1;count 49; j+
6、,count+)dayscount.setLabel();void setVal(Date date,int iday,int iselMonth,int iselYear)gc.setTime(date);if(iselMonth=0 | iselMonth=2 | iselMonth=4 | iselMonth=6 | iselMonth= 7 |iselMonth=9 | iselMonth=11)totdays=31;setButtons(iday,totdays);if(iselMonth=3 | iselMonth=5 | iselMonth=8 | iselMonth=10)to
7、tdays=30;setButtons(iday,totdays);if(gc.isLeapYear(iselYear) & iselMonth=1)totdays=29;setButtons(iday,totdays);if( !gc.isLeapYear(iselYear) & iselMonth=1)totdays=28;setButtons(iday,totdays);static public void main(String args)CalenderCreator c=new CalenderCreator();class myLis implements ItemListene
8、rCalenderCreator calLis;public myLis(CalenderCreator c)calLis=c;public void itemStateChanged(ItemEvent i)int selMonth=calLis.Month.getSelectedIndex();int selYear1=Integer.parseInt(calLis.Year.getSelectedItem();int selYear = selYear1- 1900;Date d1 = new Date(selYear,selMonth,1);int day = d1.getDay();
9、calLis.setVal(d1,day,selMonth,selYear);class myAction implements ActionListenerCalenderCreator calAc;int newyear;public myAction(CalenderCreator ca)calAc=ca;public void actionPerformed(ActionEvent e)String s=calAc.textfield.getText();/ newyear=Integer.parseInt(s);System.out.println(Year upto:+s);calAc.setYear(s);TextField tf = (TextField)e.getSource();tf.removeActionListener(this);