java日历源代码分析_java作的日历的源代码 - 编程入门网

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("JAN");

Month.add("FEB");

Month.add("MAR");

Month.add("APR");

Month.add("MAY");

Month.add("JUN");

Month.add("JUL");

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值