如果您无法下载资料,请参考说明:
1、部分资料下载需要金币,请确保您的账户上有足够的金币
2、已购买过的文档,再次下载不重复扣费
3、资料包下载后请先用软件解压,在使用对应软件打开
GetMessage.java服务端:importjava.io.BufferedReader;importjava.io.FileReader;importjava.io.IOException;importjava.io.InputStreamReader;importjava.net.ServerSocket;importjava.net.Socket;importjavax.swing.JLabel;importjavax.swing.JTextArea;publicclassGetMessageextendsThread{privateinti;Stringv;JLabellabel=null;privateJTextAreatext;publicGetMessage(inti,JTextAreatext){this.i=i;this.text=text;}publicvoidrun(){try{ServerSocketso=newServerSocket(i);Sockets=so.accept();while(true){InputStreamReaderi=newInputStreamReader(s.getInputStream());BufferedReaderb=newBufferedReader(i);v=b.readLine();text.append("对方说"+v+"\n");}}catch(IOExceptione){//label.setText("对方已经下线");text.append("对方下线了。。。");}}}SendMessage.java客户端:importjava.io.BufferedReader;importjava.io.IOException;importjava.io.InputStreamReader;importjava.io.PrintStream;importjava.net.Socket;importjava.net.UnknownHostException;importjavax.swing.JLabel;importjavax.swing.JTextArea;importjavax.swing.JTextField;publicclassSendMessageextendsThread{privateStringip;privateinti;Sockets=null;JLabellabel=null;JTextFieldtext;JTextAreatext1;publicSendMessage(Stringip,inti,JTextAreatext1){//TODOAuto-generatedconstructorstubthis.ip=ip;this.i=i;this.text1=text1;}publicvoidrun(){while(true){try{s=newSocket(ip,i);text1.setText("连接成功"+"\n");break;}catch(Exceptione){try{Thread.sleep(1000);}catch(InterruptedExceptione1){System.out.println("出错了。。。。");}}}}publicvoidsend(Stringmessage){try{PrintStreamp=newPrintStream(s.getOutputStream());p.println(message);}catch(Exceptione1){System.out.println("异常"+e1.getMessage());}}}Test.java简单的界面和测试类importjava.awt.*;importjava.awt.event.*;importjava.io.ByteArrayInputStream;importjava.io.InputStream;importjava.util.*;importj