資源簡介
自己寫的Java聊天室,實現(xiàn):客戶端通信,可顯示在線用戶,服務器端向用戶發(fā)送系統(tǒng)消息等

代碼片段和文件信息
import?java.awt.event.ActionEvent;
import?java.awt.event.ActionListener;
import?java.awt.event.WindowAdapter;
import?java.awt.event.WindowEvent;
import?java.io.IOException;
import?java.io.objectInputStream;
import?java.io.objectOutputStream;
import?java.net.Socket;
import?java.net.UnknownHostException;
import?java.util.logging.Level;
import?java.util.logging.Logger;
/*
?*?To?change?this?template?choose?Tools?|?Templates
?*?and?open?the?template?in?the?editor.
?*/
/*
?*?ChatClient.java
?*
?*?Created?on?2010-10-17?17:31:15
?*/
/**
?*
?*?@author?asus
?*/
public?class?ChatClient?extends?javax.swing.Jframe?implements?ActionListener{
????String?ip?=?“127.0.0.1“;
????int?port?=?9000;
????String?userName?=?“大果凍“;
????int?type?=?0;//0表示未連接,1表示已連接
????Socket?socket;
????objectInputStream?is;
????objectOutputStream?os;
????ClientReceive?recThread;
????
????/**?Creates?new?form?ChatClient?*/
????public?ChatClient()?{
????????initComponents();
????????this.settitle(“聊天室客戶端“);
????????//為Button添加監(jiān)聽
????????inButton.addActionListener(this);
????????offButton.addActionListener(this);
????????userButton.addActionListener(this);
????????exitButton.addActionListener(this);
????????//添加系統(tǒng)消息監(jiān)聽
????????sendButton.addActionListener(this);
????????jtf.addActionListener(this);
????????this.addWindowListener(new?WindowAdapter(){
????????????@Override
????????????public?void?windowClosing(WindowEvent?e)
????????????{
????????????????if(type?==?1)
????????????????????disConnect();
????????????????System.exit(0);
????????????}
????????});
????}
????/**?This?method?is?called?from?within?the?constructor?to
?????*?initialize?the?form.
?????*?WARNING:?Do?NOT?modify?this?code.?The?content?of?this?method?is
?????*?always?regenerated?by?the?Form?Editor.
?????*/
????@SuppressWarnings(“unchecked“)
????//?//GEN-BEGIN:initComponents
????private?void?initComponents()?{
????????jToolBar1?=?new?javax.swing.JToolBar();
????????userButton?=?new?javax.swing.JButton();
????????inButton?=?new?javax.swing.JButton();
????????offButton?=?new?javax.swing.JButton();
????????exitButton?=?new?javax.swing.JButton();
????????jScrollPane1?=?new?javax.swing.JScrollPane();
????????jta?=?new?javax.swing.JTextArea();
????????jPanel1?=?new?javax.swing.JPanel();
????????jLabel1?=?new?javax.swing.JLabel();
????????comboBox?=?new?javax.swing.JComboBox();
????????jLabel2?=?new?javax.swing.JLabel();
????????jtf?=?new?javax.swing.JTextField();
????????sendButton?=?new?javax.swing.JButton();
????????showStatus?=?new?javax.swing.JTextField();
????????setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
????????jToolBar1.setRollover(true);
????????userButton.setText(“用戶設置“);
????????userButton.setFocusable(false);
????????userButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
????????userButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
????????jToolBar1.add(userButton);
????????inButton.s
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????9879??2010-10-18?17:12??客戶端\客戶端\ChatClient.form
?????文件??????12884??2010-10-18?17:12??客戶端\客戶端\ChatClient.java
?????文件???????2664??2010-10-18?14:14??客戶端\客戶端\ClientReceive.java
?????文件???????7238??2010-10-18?16:54??客戶端\客戶端\UserConf.form
?????文件???????7510??2010-10-18?16:54??客戶端\客戶端\UserConf.java
?????文件??????74240??2010-10-18?22:10??JAVA聊天室說明.doc
?????文件??????10627??2010-10-18?21:31??服務器端\ChatServer.form
?????文件??????13698??2010-10-18?21:31??服務器端\ChatServer.java
?????文件????????389??2010-10-16?10:42??服務器端\Node.java
?????文件???????1939??2010-10-18?17:11??服務器端\ServerListen.java
?????文件???????4385??2010-10-18?21:36??服務器端\ServerReceive.java
?????文件???????1707??2010-10-16?17:12??服務器端\Userli
?????目錄??????????0??2010-10-18?22:10??客戶端\客戶端
?????目錄??????????0??2010-10-18?22:11??客戶端
?????目錄??????????0??2010-10-18?22:11??服務器端
-----------?---------??----------?-----??----
???????????????147160????????????????????15
- 上一篇:java ssm面試題
- 下一篇:spring-aop-4.3.8.jar
評論
共有 條評論