快速业务通道

用Java applet编写的日历 - 编程入门网

作者 佚名技术 来源 NET编程 浏览 发布时间 2012-06-21
checkLeapYear(int Year){ if(Year%4==0&&Year%100!=0){ isLeapYear=true; } if(Year%400==0) isLeapYear=true; else if(Year%4!=0){ isLeapYear=false; } return isLeapYear; } //--------------------------------- //--------计算当月天数--------------- //要输入年份的原因是要判断二月29天还是28天 public int checkMonth(int Month ,int Year){ int Dates=0; if (Month <0||Month>12){ System.out.println("Month Error"); } if(Month==1||Month==3||Month==5|| Month==7||Month==8||Month==10|| Month==12){ Dates=31; } if(Month==2&&this.checkLeapYear(Year)){ Dates=29; } if(Month==2&&!this.checkLeapYear(Year)){ Dates=28; } if(Month==4||Month==6||Month==9||Month==11){ Dates=30; } return Dates; } //------------------------------------ //-----用递归法计算目标年到已知年的总天数--- public int counterYearDates(int EnterYear){ int sum1=0; if(EnterYear==2001){//2001年为已知年 sum1=0; //递归从此跳出 } if(EnterYear>2001){ sum1+=this.checkYear(EnterYear-1) +this.counterYearDates(EnterYear-1); } //当目标年大于2001年,则从目标年-1往前累加 //到2001年为止 if(EnterYear<2001){ sum1+=this.checkYear(EnterYear) +this.counterYearDates(EnterYear+1); } //当目标年小于2001年,则从目标年往后累加 //到2001年为止 return sum1; } //-----计算目标年从一月到目标月的总天数------------------------ //要输入年份的原因是要判断二月29天还是28天 public int counterMonthDates(int EnterMonth,int EnterYear){ int sum2=0; if(EnterMonth==1){ sum2=0; } if(EnterMonth>1&&EnterMonth<=12){ sum2+=this.checkMonth(EnterMonth-1,EnterYear) +this.counterMonthDates(EnterMonth-1,EnterYear); } else if(EnterMonth<0){ System.out.print("Month Error"); } return sum2; } //------------------------------------------------ //-------------用数组存目标月日期----------------------------- public int[] Array(int AllDates,int EnterMonth){ int n=AllDates%7; int a=1; int[] DayInTable=new int[38]; if(n<0)//Keep the n bigger than 0 n=7+n+1;//Line 207 haven´t add 1,so here add if(n!=0) for(int i=n;i<this.checkMonth(EnterMonth,EnterYear)+n;i++){ DayInTable[i]=a; a++; } else for(int i=7;i<this.checkMonth(EnterMonth,EnterYear)+7;i++){ //若n为0,则说明目标月一号为星期日 DayInTable[i]=a; a++; } return DayInTable; } //---------------------------------------------------------- //-----------打印输出------------------------------- public void printTable(int[]DayInTable){ System.out.println("Curren Date is: Year " +EnterYear+" Month "+EnterMonth); System.out.print("Mon Tue Wed Thur Fri Sat Sun "); System.out.println(); for(int i=1;i<=37;i++){ if(DayInTable[i]==0) System.out.print(" "); if(i%7==0&&DayInTable[i]!=0){ //防止在最后i=35时输出0 System.out.print(DayInTable[i]+" "); System.out.println(); } else if(DayInTable[i]>9) System.out.print(DayInTable[i]+" "); else if(DayInTable[i]!=0) //防止在最后i<9时输出0 System.out.print(DayInTable[i]+" "); if(i==37) System.out.println(); } } //----------------

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号