简易聊天
源代码在线查看: message.java
import java.sql.*; //继承了java.util.Date
import java.io.Serializable;
import java.sql.Timestamp;
//date.toLocaleString()方法has been deprecated
class Message implements Serializable{
String fromName;
String toName;
String msg="";
Date date=null; //是msg对应的时间
String strdate; //date的字符串表示
String strLocaledate; //date的本地字符串表示
private Message(String fromName,String toName){
this.fromName=fromName;
this.toName=toName;
}//Message(String fromName,String toName)
public Message(String fromName,String toName,String msg,long date){
this(fromName,toName);
this.msg=msg;
this.date=new Date(date);
this.strLocaledate=this.date.toLocaleString();
this.strdate=this.date.toGMTString();
}//public Message(String fromName,String toName,String msg,long date)
public Message(String fromName,String toName,String msg,String date){
this(fromName,toName);
this.msg=msg;
this.date=new Date(Date.parse(date));
this.strdate=this.date.toGMTString();
this.strLocaledate=this.date.toLocaleString();
}//public Message(String fromName,String toName,String msg,long date)
public void setMsg(String msg){
this.msg=msg;
}
public void setDate(long date){
this.date=new Date(date);
}
public void setFromName(String fromName){
this.fromName=fromName;
}
public String getfromName(){
return fromName;
}
public String gettoName(){
return toName;
}
public String getMsg(){
return msg;
}
public Date getDate(){
return date;
}
public String getstrDate(){
return strdate;
}
public String getstrLocaleDate(){
return strLocaledate;
}
/*********************下面两个方法用于对PublicMessage进行调试的**************************/
public void display(){
System.out.println("发送者: "+fromName);
System.out.println("接收者: "+toName);
System.out.println("信息内容: "+msg);
System.out.println("时间: "+date.toLocaleString());
//System.out.println("时间: "+date.toGMTString());
}//public void display()
public static void main(String args[]){
new Message("SunMicrosystem","Java","Java is birthed at 1995.5.23",System.currentTimeMillis()).display();
}//public static void main(String args[])
/*********************上面两个方法用于对PublicMessage进行调试的**************************/
}//class Message