📄 smessage.java
字号:
import java.io.*;
import java.awt.*;
import java.util.*;
import javax.swing.*;
import javax.swing.text.*;
/**
* SMessage.java
*
* 传输数据所用的对象类型
* 对所传对象的处理
*
* @author 戚荣波
*
* @version 1.0
* @since J2SE 1.6
*/
public class SMessage implements Serializable
{
private static final long serialVersionUID = 1234567L;
/**系统消息*/
public static final int MT_SYSTEM = 1; //系统消息
/**文字消息*/
public static final int MT_MESSAGE = 2;//文字消息
/**姓名消息*/
public static final int MT_NAME = 3;//姓名消息
/**断开消息*/
public static final int MT_DISCONNECT = 4;//断开消息
/**文件传输请求*/
public static final int MT_FILE = 5;//文件传输请求
/**闪屏消息*/
public static final int MT_SHOCK = 6;//闪屏消息
/**图像消息*/
public static final int MT_PICTURE = 7;//图像消息
/**请求的同意回应*/
public static final int MT_AGREE = 8;//请求的同意回应
/**请求的拒绝回应*/
public static final int MT_REFUSE = 9;//请求的拒绝回应
/**表示表情的开头*/
public static final char STR_FACE = (char)0xEEEE;
private int messageType = 0;
private String str = null;
private SimpleAttributeSet att = null;
private String nowTime = null;
/**
*获得消息中的文字
*
*@return 文字内容
*/
public String getString()
{
return str;
}
/**
*获得文件长度
*
*@return 文件长度
*/
public long getFileLength()
{
if(messageType == MT_FILE||messageType == MT_PICTURE)return Long.parseLong(nowTime);
else return 0L;
}
/**
*获得消息类型
*
*@return 消息类型
*/
public int getMessageType()
{
return messageType;
}
/**
*
*@param messageType2 消息类型
*@param nowTime2 消息发出时的时间 当messageType2为MT_FILE时表示文件长度
*@param str2 当messageType2为MT_MESSAGE时表示文字内容
*@param att2 当messageType2为MT_MESSAGE时表示内容格式
*/
public SMessage(int messageType2,String nowTime2,String str2,SimpleAttributeSet att2)
{
this.messageType = messageType2;
this.str = str2;
this.att = att2;
this.nowTime = nowTime2;
}
/**
*获得系统当前时间
*
*@return 系统当前时间
*/
public static String getTime()
{
Calendar c = Calendar.getInstance();
int h = c.get(Calendar.HOUR);
int m = c.get(Calendar.MINUTE);
int s = c.get(Calendar.SECOND);
String t =" " + h + ":" + m + ":" + s;
return t;
}
/**
*输出MT_MESSAGE的消息
*
*@param name 消息发送者
*@param tp 消息输出目标
*/
public void append(String name,JTextPane tp)
{
StyledDocument doc = tp.getStyledDocument();
if(messageType != MT_MESSAGE)return;
SChattingFrame.audioPlay("type.wav");
try
{
SomethingStored.fontBar.setVisible(false);
doc.insertString(doc.getLength(),name + nowTime +":\n",SomethingStored.defaultAttributeSet);
doc.insertString(doc.getLength(),str,att);
tp.setCaretPosition(doc.getLength());
}
catch(BadLocationException exp)
{
System.err.println("BadLocationException:"+exp);
exp.printStackTrace();
}
catch(Exception exp)
{
System.err.println("Exception:"+exp);
exp.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -