talent_marquis (甜菜侯爵) :  我觉得你的两种思路实际上还是一种思路,因为不管格式与文字一起发送,还是分开发送,到达接受端后都要进行格式的解析。只不过在解析的时候可能有两种,一种是边接受边解析,另外就是分段解析或者一次性解析。

解决方案 »

  1.   

    如果是第一种方法的话,我就必须自己写一个解析格式的类
    就算我的文字格式仅仅包括字体类型、字体大小、字体颜色,实际操作判断起来仍然是非常繁琐的我想知道Java本身是否就能够支持带格式文字的流化和流的逆转呢?
      

  2.   

    所有的文字都是字节流,你可以用Socket发送到接收端。流化和逆转都是你程序逻辑要做的事。
      

  3.   

    但是我查阅Java2学习手册(第二版)发现它里面有一个介绍输入输出串行化的问题,和我说的意图很接近啊(书P363页)
    但是介绍的很简略,我看不大懂
    不知道有没有人对串行化这个东东很了解呢?
      

  4.   

    比如说
    ll 是有格式的字
    你写个内部类
    比如 kk 
    然后用
    kk.ll = ll.getText();
    当你传的时候就可以把所有的传过去了
    要传类,在接收的时候再专成ll相对的类型就可以了
      

  5.   

    不知道这样可以不
    把你的这些文字转化为字节流用socket收发通讯,然后另一端具体的解析。或者用xml文档定义各个含义,然后收发解析。
      

  6.   

    我自己通过一个折衷的方法解决了,给大家看看我写的分析格式的类 ^ ^import java.util.regex.*;
    import java.awt.*;class FormatText
    {
    private String formatText="";
    private String nickName,fname,content;
    private String[] resolveText;
    private int fType,fSize,cR,cG,cB;
    private Color fColor;

    public FormatText(){}

    //文字名称,文字类型,文字大小,文字颜色,正文
    public void setFormatText(String nickName,String fName,int fType,int fSize,int cR,int cG,int cB,String  content)
    {
    formatText=nickName+"╋"+fName+"╋"+fType+"╋"+fSize+"╋"+cR+"╋"+cG+"╋"+cB+"╋"+content;
    resolveFormatText();
    }
    public String getNickName()
    {
    return nickName;
    }
    public String getFormatText()
    {
    return formatText;
    }
    public String getFontName()
    {
    return fname;
    }
    public int getFontType()
    {
    return fType;
    }
    public int getFontSize()
    {
    return fSize;
    }
    public Color getFontColor()
    {
    fColor=new Color(cR,cG,cB);
    return fColor;
    }
    public String getTextContent()
    {
    return content;
    }
    public boolean getFontBold()
    {
    if(fType==1 || fType==3)
    return true;
    else
    return false;
    }
    public boolean getFotnItalic()
    {
    if(fType==2 || fType==3)
    return true;
    else 
    return false;
    }

    private void resolveFormatText()
    {
    resolveText=Pattern.compile("╋").split(formatText,8);

    nickName=resolveText[0];
    fname=resolveText[1];
    fType=Integer.parseInt(resolveText[2]);
    fSize=Integer.parseInt(resolveText[3]);
    cR=Integer.parseInt(resolveText[4]);
    cG=Integer.parseInt(resolveText[5]);
    cB=Integer.parseInt(resolveText[6]);
    content=resolveText[7];

    }