📄 scheduleitem.java
字号:
//ScheduleItem.java 保存日程记录
package calendar;
import java.util.*;
import java.io.*;
public class ScheduleItem
{
//定义日程类型
public final static int PHONE =0;
public final static int MEETING =1;
public final static int TASK =2;
public final static int EMAIL =3;
public final static int NOTE =4;
public final static int MISC =5;
//定义类型名称
protected final static String[ ] typeName={"Phone","Meeting","Task","Email","Note","Misc"};
public int itemType; //日程类型
public Date itemTime; //日程日期和时间
public String itemName, itemMemo; //日程名称和说明
//构造器
public ScheduleItem()
{
itemType = MISC;
itemTime = new Date(0);
itemName = null;
itemMemo = null;
}
//将数据转换为字节数组
public byte[ ] getBytes()
{//利用ByteArrayOutputStream 和 DataOutputStream 来完成这个操作
ByteArrayOutputStream bdos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream( bdos );
byte[ ] retV = null;
try
{
dos.writeInt(itemType);
dos.writeLong(itemTime.getTime());
dos.writeUTF(itemName);
dos.writeUTF(itemMemo);
retV = bdos.toByteArray();
dos.close();
bdos.close();
}
catch(IOException e) { System.out.println(e.getMessage()); }
finally
{
dos = null;
bdos = null;
}
return retV;
}
//从字节数组中将数据读出,并转换为数据
public boolean readBytes(byte[] src)
{//ByteArrayInputStream 和 DataInputStream 来完成这个操作
ByteArrayInputStream bdis = new ByteArrayInputStream(src);
DataInputStream dis = new DataInputStream( bdis );
boolean retV = false;
try
{
itemType = dis.readInt();
itemTime.setTime(dis.readLong());
itemName = dis.readUTF();
itemMemo = dis.readUTF();
retV = true;
dis.close();
bdis.close();
}
catch(IOException e)
{ System.out.println(e.getMessage()); }
finally
{
dis = null;
bdis = null;
}
return retV;
}
//通过日程类型的值得到类型名称
public static String getTypeName(int type)
{
return typeName[type];
}
//设置对象的值
public void set(String name,int type,Date date,String memo)
{
itemName = name;
itemType = type;
itemMemo = memo;
itemTime = date;
}
//检查年月日是否与参数中指定的日期相同
public boolean isDateMatch(Calendar date)
{
Calendar cal = Calendar.getInstance();
cal.setTime(itemTime);
return (cal.get(Calendar.DAY_OF_MONTH) == date.get(Calendar.DAY_OF_MONTH)
&& cal.get(Calendar.MONTH) == date.get(Calendar.MONTH)
&& cal.get(Calendar.YEAR) == date.get(Calendar.YEAR));
}
//得到用1970/1/1日来表示的时间,这是为了能够让时间用于DateField对象
public Date getTime()
{
Calendar cal = Calendar.getInstance();
cal.setTime(itemTime);
cal.set(Calendar.YEAR,1970);
cal.set(Calendar.MONTH,Calendar.JANUARY);
cal.set(Calendar.DAY_OF_MONTH,1);
return cal.getTime();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -