Make your own free website on Tripod.com

/**This Original Java Code is written by me

*You have to enter the month first and then the year later in the format mm/yyyy

*this Calendar works from 1900-2038

*.This program has some bugs.

* I will remove in my later versions.

* <applet code=Car.class width=640 height=550>

* </applet>

* You can modify this code and distribute among your friends

* Original Programmed by : A. LEVI.

* My e-mail address is levi57@hotmail.com * -still unemployed- */

import java.awt.*;

import java.util.*;

import java.applet.*;

public class Calendar extends Applet

{

int days[] = { 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 };

String week[] = {"Sun","Mon","Tues","Wed","Thur","Fri","Sat"};

String month[] = {"January","February","March","April","May","June","July","August","September","October","November","December"};

Date d;

TextField tf;

Button but;

date dt;

public void init()

{

setLayout(null);

setBackground(Color.white);

tf = new TextField();

but = new Button("Ok");

but.reshape(370,500,75,25);

tf.reshape(230,500,120,25);

add(tf); add(but);

d = new Date();

}

public boolean action(Event e , Object o)

{

if(o.equals("Ok"))

{

String str = tf.getText();

dt = new date();

if( dt.parseDate(str) )

{

d = new Date( (dt.yy-1900) ,(dt.mm-1),1);

repaint();

}

else

{

d = new Date();

repaint();

}

}

return true;

}

public void paint(Graphics g)

{

g.setColor(Color.green);

g.fillRect(50,30,550,30);

g.setColor(new Color(176,176,176));

for(int j=0;j<=360;j+=60)

for(int i=0;i<560;i+=80)

g.fillRect(50+i,80+j,70,50);

g.setColor(Color.black);

Font f = new Font("TimesRoman",Font.BOLD,20);

g.setFont(f);

g.drawString("Any Date (mm/yy):",50,520);

for(int i=0;i<560;i+=80)

g.drawString(week[i/80],70+i,110);

int m = d.getMonth();

Date nd = new Date(d.getYear(),d.getMonth(),1);

g.drawString(month[m],280,50);

int date = nd.getDay();

if( nd.getYear()%4==0 )

days[1] = 29;

int row=0; int col= date * 80;

for(int i=1;i<=days[m];i++)

{

if(col>480)

{

col = 0;

row+=60;

}

g.drawString(""+i,col+75,row+170);

if( i == d.getDate())

{

g.setColor(Color.red);

g.drawString(""+i,col+75,row+170);

}

col+=80;

g.setColor(Color.black);

}

}

}

class date

{

String mm_string,yy_string;

int yy;

int mm;

boolean parseDate(String s)

{

StringTokenizer st = new StringTokenizer(s,"/");

if( st.countTokens() != 2 )

{

return false;

}

else

{

mm_string = st.nextToken();

yy_string = st.nextToken();

try

{

mm = Integer.parseInt(mm_string);

yy = Integer.parseInt(yy_string);

}catch(NumberFormatException nfe)

{

return false;

}

if( mm > 12 || yy < 1900 )

{

return false;

}

}

return true;

}

}