📄 mydate.java
字号:
/****************************************************************************************
* Java日历程序
* 作者:张亚航
*
* 完成时间:2008-5-22
*
* 程序功能:
* Model包中的MyDate类是程序日历的载体,本程序没有使用JDK的类库java.util.Date和
* java.util.Calendar类,而是重新构造了MyDate类,该类只能保存精度到日的时间
*
* MyDate类中主要字段包括year,month,date和daysOfMonth
*
******************************************************************************************/
package model;
import java.util.*;
import control.ComputeDate;
//本程序实现clone方法
public class MyDate implements Cloneable
{
int year = 0; //年
int month = 0; //月
int date = 0; //日
int daysOfMonth = 0; //当月总天数
public MyDate()
{
this.year = new Date().getYear()+1900;
this.date = new Date().getDate();
this.month = (new Date().getMonth()+1)%12;
}
public String toString()
{
return "Year:"+this.year+" Month:"+this.month+" Date"+this.date;
}
public int getDate()
{
return this.date;
}
public int getMonth()
{
return this.month;
}
public int getYear()
{
return this.year;
}
public void setDate(int date)
{
this.date = date;
}
public void setYear(int year)
{
this.year = year;
}
public void setMonth(int month)
{
this.month = month;
}
public int getDaysOfMonth()
{
this.daysOfMonth= (int) new ComputeDate().getDaysOfMonth(this);
return this.daysOfMonth;
}
public static void main(String arg[])
{
MyDate a = new MyDate();
System.out.println(a.year);
System.out.println(a.month);
System.out.println(a.date);
}
/****************实现对象克隆************************/
public Object clone()
{
Object o = null;
try
{
o = super.clone();
}
catch(CloneNotSupportedException e)
{
System.err.println("MyObject can't clone");
}
return o;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -