资源简介

多用户之间的信息共享,绘图区绘图共享,可以聊天并且发表情

资源截图

代码片段和文件信息

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;

import javax.swing.Jframe;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

public class Client extends Jframe implements Runnable{
JTextArea text;
JScrollBar vsBar;
Socket socket;
BufferedReader sin;
PrintWriter os;
BufferedReader is;
JTextField sendField;
JTextField nameField;
Client() throws UnknownHostException IOException{
this.settitle(“TCP聊天室客户端--戴云磊“);
    this.setBounds(100200400400);
    this.setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE);
    this.setVisible(true);
        this.setLayout(new BorderLayout());
        text=new JTextArea();
     sendField = new JTextField();
     nameField=new JTextField();
        text.setEditable(false);
        JScrollPane textPanel=new JScrollPane(text);
        vsBar = textPanel.getVerticalScrollBar();
        this.add(textPanelBorderLayout.CENTER);
        this.add(nameFieldBorderLayout.NORTH);
        this.add(sendFieldBorderLayout.SOUTH);
        sendField.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
os.println(nameField.getText()+“:“+sendField.getText());
os.flush();
sendField.setText(null);
}
});
}
public void textappend(String str){
text.append(str+“\n“);
}
public void getsocket() throws UnknownHostException IOException{
textappend(“聊天准备完毕“);
textappend(“请在上方输入你的用户名“);
socket = new Socket(InetAddress.getByName(null)4714);
os=new PrintWriter(socket.getOutputStream());
    is=new BufferedReader(new InputStreamReader(socket.getInputStream()));
    new Thread(this).start(); // 启动线程    
}
public void run(){
while (true) {
try {
text.append(is.readLine()+“\n“);
} catch (Exception e) {
e.printStackTrace();
}
}
}
public static void main(String [] args) throws UnknownHostException IOException{
Client client=new Client();
client.getsocket();
Painting pa=new Painting();
pa.send();
while(true){
pa.run();
}
}
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2013-01-08 17:08  testing\
     文件         301  2013-01-08 17:08  testing\.classpath
     文件         383  2013-01-08 17:08  testing\.project
     目录           0  2013-01-08 17:08  testing\.settings\
     文件         598  2013-01-08 17:08  testing\.settings\org.eclipse.jdt.core.prefs
     目录           0  2013-01-08 12:42  testing\bin\
     文件        1159  2013-01-08 12:42  testing\bin\Client$1.class
     文件        3432  2013-01-08 12:42  testing\bin\Client.class
     文件        2119  2013-01-08 12:42  testing\bin\MultiServer$ReadThread.class
     文件        2378  2013-01-08 12:42  testing\bin\MultiServer.class
     文件         894  2013-01-08 12:42  testing\bin\Painting$1.class
     文件         593  2013-01-08 12:42  testing\bin\Painting$Bt1.class
     文件         593  2013-01-08 12:42  testing\bin\Painting$Bt2.class
     文件         593  2013-01-08 12:42  testing\bin\Painting$Bt3.class
     文件         593  2013-01-08 12:42  testing\bin\Painting$Bt4.class
     文件        6679  2013-01-08 12:42  testing\bin\Painting.class
     文件        2029  2013-01-08 12:42  testing\bin\Point.class
     文件        1938  2013-01-08 12:42  testing\bin\Server.class
     目录           0  2013-01-08 12:39  testing\src\
     文件        2422  2013-01-08 12:41  testing\src\Client.java
     文件        2388  2013-01-08 12:41  testing\src\MultiServer.java
     文件        5586  2013-01-08 12:41  testing\src\Painting.java
     文件        2031  2013-01-07 11:16  testing\src\Point.java
     文件        1170  2013-01-08 12:41  testing\src\Server.java

评论

共有 条评论