Java as the source of the calendar

Source: Internet
Author: User

Import java.awt.*;


import java.awt.event.*;


import java.util.*;


public class Calendercreator extends Frame


{


Button days[]=new button[49];


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 gc=new GregorianCalendar ();


int totdays;


TextField textfield=new TextField (2);


public calendercreator ()


{


Settitle ("This is a calender");


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.red);


P2.setbackground (Color.cyan);


Add (P1,borderlayout.north);


Add (p2);


P1.add (Ltext);


P1.add (TextField);


P1.add (Lmonth);


P1.add (Month);


Month.add ("the");


Month.add ("FEB");


Month.add ("MAR");


Month.add ("APR");


Month.add ("may");


Month.add ("June");


Month.add ("June");


Month.add ("AUG");


Month.add ("SEP");


Month.add ("OCT");


Month.add ("NOV");


Month.add ("DEC");


Month.additemlistener (New Mylis (this));


//int i1=myaction.newyear; //


//System.out.println ("IIIIIIIIII is::::::" +i1); //


Textfield.addactionlistener (New myaction (this)); //


P1.add (lyear);


P1.add (year);


Year.add ("1990");


/* Year.add ("1991");


Year.add ("1992");


Year.add ("1993");


Year.add ("1994");


Year.add ("1995"); */


Year.additemlistener (New Mylis (this));


for (int i=0;i<49;i++)


{


days[i]=new button ("");


}


for (int c=0;c<49;c++)


{


P2.add (Days[c]);


}


setvisible (TRUE);


}


void Setyear (String mynewyear)


{


int H=integer.parseint (mynewyear);


for (int adder=1991;adder<=h;adder++)


{


Year.add ("" +adder);


}


}


void setbuttons (int myday,int mytotdays)


{


int count=7;


Days[0].setlabel ("SUN");


Days[1].setlabel ("MON");


Days[2].setlabel ("TUE");


Days[3].setlabel ("WED");


Days[4].setlabel ("Thur");


Days[5].setlabel ("FRI");


Days[6].setlabel ("SAT");


if (myday>0)


{


int blank= myday;


for (; Blank>0;blank--, count++)


{


Days[count].setlabel ("");


}


}


for (int i=1;i<=mytotdays; i++,count++)


{


Days[count].setlabel ("" +i);


}


for (int j = 1;count < j++,count++)


{


Days[count].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)


{


totdays=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 ItemListener


{


Calendercreator 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 ();


Callis.setval (d1,day,selmonth,selyear);


}


}


class Myaction implements ActionListener


{


Calendercreator 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);


}


}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.