日历程序望赐教
这里有个万年历的程序 为什么运行之后没有结果 望各位大侠不吝赐教import java.applet.*;
import java.awt.*;
import java.util.*;
class calendar extends Applet
{
Graphics g;
Font font;
FontMetrics fm;
Date current_date;
Date month_to_show;
int width;
int height;
int year;
int month;
public void init()
{
g=getGraphics();
current_date=new Date();
year=current_date.getYear();
month=current_date.getMonth();
month_to_show=new Date(year,month,1);
Panel p=new Panel();
add("North",p);
p.add(new Button("<"));
p.add(new Button(">"));
}
public boolean action(Event evt,Object arg)
{
if(arg.equals("<"))
{
if(--month<0)
{
month=11;
year--;
}
}
else
{
if(++month>11)
{
month=1;
year++;
}
}
month_to_show=new Date(year,month,1);
repaint();
return true;
}
String day_of_week(int day)
{
switch(day)
{
case 0:return("Sun");
case 1:return("Mon");
case 2:return("Tue");
case 3:return("Wed");
case 4:return("Thu");
case 5:return("Fri");
default:return("Sun");
}
}
String month_name(int month)
{
switch(month)
{
case 0:return("January");
case 1:return("February");
case 2:return("March");
case 3:return("April");
case 4:return("May");
case 5:return("June");
case 6:return("July");
case 7:return("August");
case 8:return("September");
case 9:return("October");
case 10:return("November");
default:return("December");
}
}
int number_of_days(int month,int year)
{
switch(month+1)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
return(31);
case 4:
case 6:
case 9:
case 11:
return(30);
default:
if(year%4!=0)
return(28);
else
if(year%100!=0)
return(29);
else
if(year%400!=0)
return(28);
else
return(29);
}
}
public void paint(Graphics g)
{
width=size().width;
height=size().height;
if(width<height)
height=width;
else
width=height;
g.setColor(Color.blue);
g.fillRect(0,0,size().width,size().height);
g.setColor(Color.white);
for(int i=2;i<9;i++)
{
int y=(height*i)/8;
g.drawLine(0,y,width-1,y);
}
int y=height/4;
for(int i=0;i<8;i++)
{
int x=(width*i)/7;
g.drawLine(x,y,x,height-1);
}
font=new Font("TimesRoman",Font.BOLD,height/20);
g.setFont(font);
//font_metrics=g.getFontMetrics();
g.drawString(month_name(month_to_show.getMonth())+""+(1900+month_to_show.getYear()),0,height/8);
y=height/4;
for(int i=0;i<7;i++)
{
g.drawString(day_of_week(i),(width*i)/7,y);
}
int first=month_to_show.getDay();
int last=number_of_days(month_to_show.getMonth(),month_to_show.getYear());
int day=first;
y=(height*5)/16;
for(int i=1;i<=last;i++)
{
g.drawString(""+i,(width*day)/7,y);
if(++day>6)
{
day=0;
y+=height/8;
}
}
}
public static void main(String args[])
{
calendar c=new calendar();
}
}