下面这段代码是客户段代码,是从一本书上抄下来的,就是从客户短键盘输入一些信息然后在服务器端的标准输出流打印出来才,想问下大家,我想把这个消息打在一个文本框内(比如用java.swing做的 ),让每发一次消息,就在文本框打印出来才,类似于聊天程序那样,我该怎么来实现,java.swing 这个包我不熟,哪位高手可否告诉我该怎么做才,代码是谢谢!!服务端的代码我就不写了,我想大家应该很清楚的!
import java.net.*;
import java.io.*;
public class TestClient
{
public static void main(String[] args) throws Exception
{

Socket soc=null;
InputStream is=null;
OutputStream os=null;
DataInputStream  in=null;
PrintStream out=null;
String strin=null;
try{
soc=new Socket("localhost",8000);
System.out.println("connect to  the  server");
is=soc.getInputStream();
os=soc.getOutputStream();
in=new DataInputStream(is);
out=new PrintStream(os);
strin=in.readLine();
System.out.println("sever said"+strin);
byte bmsg[]=new byte[20];
System.in.read(bmsg);
String msg=new String(bmsg,0);
msg=msg.trim();
while(!msg.equals("quit")){
out.println(msg);
System.in.read(bmsg);
msg=new String(bmsg,0);
msg=msg.trim();

}
out.println(msg);

}
catch(Exception e){
System.out.println(e);
}
finally{
is.close();
os.close();
soc.close();
System.exit(0);
}

}
}

解决方案 »

  1.   

    不知道Swing的时候可以在Console下写啊,你看人家玩Linux的,在命令行在wget,收个email都乐得屁颠屁颠的。
      

  2.   

    实际上,你这个问题牵扯了很多深刻的问题,比如Swing和线程的关系。唉,你就先命令行吧。
      

  3.   

    who  can  help me ...?thanks!
      

  4.   

    我刚写了一个简单聊天室的,不知道对你有没有帮助。你完全可以只用awt就可以。不妨把你邮箱给我,我把写的源代码发给你。