Java 多人聊天 源码
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Java 多人聊天源码
1.ChatApplet.java类
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
import yout.*;
import javax.swing.border.*;
import java.io.*;
import .*;
public class ChatApplet extends JApplet {
boolean isStandalone = false;
BorderLayout borderLayout1 = new BorderLayout();
Border border1;
JPanel jPanel2 = new JPanel();
Border border2;
BorderLayout borderLayout2 = new BorderLayout();
JPanel jPanel1 = new JPanel();
JButton buttonSend = new JButton();
BorderLayout borderLayout3 = new BorderLayout();
JPanel jPanel3 = new JPanel();
Border border3;
BorderLayout borderLayout4 = new BorderLayout();
JTextField textTalk = new JTextField();
JPanel jPanel4 = new JPanel();
Border border4;
BorderLayout borderLayout5 = new BorderLayout();
JScrollPane jScrollPane1 = new JScrollPane();
JTextArea textMessages = new JTextArea();
PrintWriter out = null;
/**Get a parameter value*/
public String getParameter(String key, String def) {
return isStandalone ? System.getProperty(key, def) :
(getParameter(key) != null ? getParameter(key) : def); }
/**Construct the applet*/
public ChatApplet() {
}
/**Initialize the applet*/
public void init() {
try {
jbInit();
Client client = new Client(this);
if (client.isConnected())
out = client.getOutputStream();
else
appendMessage("大大的错误!!");
}
catch(Exception e) {
e.printStackTrace();
}
}
/**Component initialization*/
private void jbInit() throws Exception {
border1 = BorderFactory.createEmptyBorder(9,9,9,9);
border2 = BorderFactory.createEmptyBorder(9,9,9,9);
border3 = BorderFactory.createEmptyBorder(2,0,2,5);
border4 = BorderFactory.createEmptyBorder(0,0,5,0);
this.setSize(new Dimension(400,300));
this.getContentPane().setLayout(borderLayout1);
jPanel2.setBorder(border2);
jPanel2.setLayout(borderLayout2);
buttonSend.setFocusPainted(false);
buttonSend.setText("发送");
buttonSend.addActionListener(new
java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
buttonSend_actionPerformed(e);
}
});
jPanel1.setLayout(borderLayout3);
jPanel3.setBorder(border3);
jPanel3.setLayout(borderLayout4);
jPanel4.setBorder(border4);
jPanel4.setLayout(borderLayout5);
textTalk.addKeyListener(new java.awt.event.KeyAdapter() { public void keyPressed(KeyEvent e) {
textTalk_keyPressed(e);
}
});
this.getContentPane().add(jPanel2, BorderLayout.CENTER);