| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 431 人关注过本帖
标题:日历程序望赐教
只看楼主 加入收藏
dddkl007
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2012-4-5
结帖率:100%
收藏
已结贴  问题点数:10 回复次数:1 
日历程序望赐教
这里有个万年历的程序 为什么运行之后没有结果 望各位大侠不吝赐教
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();
    }
}
搜索更多相关主题的帖子: 万年历 日历 calendar public import 
2012-04-06 20:42
lucky563591
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:4
帖 子:765
专家分:2103
注 册:2009-11-18
收藏
得分:7 
没有show吧
2012-04-07 09:51
快速回复:日历程序望赐教
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.049911 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved