import java.net.*; import java.io.*; import java.awt.*; class AdviseThread extends Thread { SocketControl mSocketControl=null; List mList; public final int AdvisePort=200; private boolean mIsCancelled=false; private final String mUserTalkDirective=new String("USERTALK("); private final String mUserEnterDirective=new String("USERENTER("); private final String mUserLeaveDirective=new String("USERLEAVE("); private final String mQuitDirective=new String("QUIT"); public AdviseThread(List list) { mList=list; isCancelled(false); mSocketControl=new SocketControl(); } public void run() { String strLine=null; String strAdvise=new String(); try{mSocketControl.accept(AdvisePort);} catch(IOException exception){return;} mSocketControl.writeLine("TESTCONNECT"); while(true) { strLine=new String(); strLine=mSocketControl.readLine(); if(isCancelled())break; if(0==strLine.length())continue; if(strLine.regionMatches(0,mUserTalkDirective,0,mUserTalkDirective.length()))strLine=parseTalk(strLine); else if(strLine.regionMatches(0,mUserEnterDirective,0,mUserEnterDirective.length()))strLine=parseEnter(strLine); else if(strLine.regionMatches(0,mUserLeaveDirective,0,mUserLeaveDirective.length()))strLine=parseLeave(strLine); else if(strLine.regionMatches(0,mQuitDirective,0,mQuitDirective.length()))break; mList.addItem(strLine); mList.select(mList.getItemCount()-1); } stop(); } public void isCancelled(boolean isCancelled) { mIsCancelled=isCancelled; if(mIsCancelled) { try{mSocketControl.closeSocket();} catch(IOException exception){return;} } } public boolean isCancelled() { return mIsCancelled; } private String parseTalk(String strLine) { int strLength=strLine.length(); String strUser=new String(); String strString=new String(); String strReturn=new String(); int index=0; while(index