資源簡介
本次開發實現了一個多用戶的在線聊天程序,C/S結構,客戶端可發送消息,然后其他的用戶接收到該消息并將其顯示在界面中,服務器對信息進行有關處理并向適當的用戶發送,同時在服務器端還將顯示所有的在線用戶,網絡管理員即服務器端管理員可選中某用戶并將其踢出該聊天室。

代碼片段和文件信息
package?Client;
import?java.awt.*;
import?java.awt.event.*;
import?java.applet.*;
import?java.net.*;
import?com.borland.jbcl.layout.*;
import?com.borland.jbcl.control.*;
/**
?*?title:?
?*
?*?Description:?
?*
?*?Copyright:?Copyright?(c)?2005
?*
?*?Company:?
?*
?*?@author?not?attributable
?*?@version?1.0
?*/
public?class?applet1?extends?applet?{
????boolean?isStandalone=false;
????Button?button1=new?Button()?;
????Label?label1=new?Label()?;
????TextField?textField1=new?TextField();
????GroupBox?groupBox1=new?GroupBox();
????TextArea?textArea1=new?TextArea();
????PaneLayout?paneLayout1=new?PaneLayout();
????PaneLayout?paneLayout2=new?PaneLayout();
????boolean?login=false;
????SimpleClient?simpleClient=null;
????static?String?userName=““;
????String?hostname=“202.117.115.228“;
????//Construct?the?applet
????public?applet1()?{
????}
????//Initialize?the?applet
????public?void?init()
????{
????????try
????????{
????????????URL?url=this.getCodebase();
????????????String?te=url.toString();
????????????String?temp=url.getHost();
????????????if(!(temp.equals(““)))
????????????????hostname=temp;?//得到服務器的ip地址
????????????else?hostname=“202.117.115.228“;
????????????jbInit();
????????}
????????catch(Exception?e)
????????{
????????????e.printStackTrace();
????????}
????}
????//Component?initialization
????private?void?jbInit()?throws?Exception
????{
????????this.setSize(new?Dimension(444263));
????????button1.setLabel(“登陸“);
????????label1.setAlignment(2);
????????label1.setText(“用戶名“);
????????textField1.addActionListener(new?applet1_textField1_actionAdapter(this));
????????groupBox1.setLayout(paneLayout1);
????????groupBox1.setLabel(“信息“);
????????button1.addActionListener(new?applet1_button1_actionAdapter(this));
????????this.setLayout(paneLayout2);
????????this.add(groupBox1new?PaneConstraints(“groupBox1““groupBox1“
???????????????????????????????????????????????PaneConstraints.ROOT0.5f));
????????groupBox1.add(textArea1new?PaneConstraints(“textArea1““textArea1“
???????????????????????????????????????????????PaneConstraints.ROOT1.0f));
????????this.add(label1new?PaneConstraints(“label1““groupBox1“
??????????????????????????PaneConstraints.BOTTOM0.09505701f));
????????this.add(textField1new?PaneConstraints(“textField1““label1“
?????????????????????????PaneConstraints.RIGHT0.83229816f));
????????this.add(button1new?PaneConstraints(“button1““textField1“
?????????????????????????PaneConstraints.RIGHT0.30223882f));
????}
????//Get?applet?information
????public?String?getappletInfo()
????{
????????return?“applet?Information“;
????}
????//Get?parameter?information
????public?String[][]?getParameterInfo()
????{
????????return?null;
????}
????public?void?destroy()
????{
????????try
????????{
????????????simpleClient.sendString(“quit“);
????????????simpleClient.stop();
????????}
????????catch(Exception?e)
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????161792??2007-12-24?11:13??P2P--多用戶在線聊天室(Java源碼)\P2P作業說明文檔.doc
?????文件???????4208??2007-12-19?19:24??P2P--多用戶在線聊天室(Java源碼)\源碼包\client\ap
?????文件???????4614??2007-12-24?10:37??P2P--多用戶在線聊天室(Java源碼)\源碼包\client\ap
?????文件????????655??2007-12-19?19:24??P2P--多用戶在線聊天室(Java源碼)\源碼包\client\ap
?????文件????????664??2007-12-19?19:24??P2P--多用戶在線聊天室(Java源碼)\源碼包\client\ap
?????文件???????1754??2007-12-19?16:45??P2P--多用戶在線聊天室(Java源碼)\源碼包\client\SimpleClient.class
?????文件???????1635??2007-12-19?16:45??P2P--多用戶在線聊天室(Java源碼)\源碼包\client\SimpleClient.java
?????文件???????2060??2007-12-19?16:46??P2P--多用戶在線聊天室(Java源碼)\源碼包\client\UserThread.class
?????文件???????1677??2007-12-19?16:46??P2P--多用戶在線聊天室(Java源碼)\源碼包\client\UserThread.java
?????文件???????1357??2007-12-19?20:23??P2P--多用戶在線聊天室(Java源碼)\源碼包\server\ServerConn.class
?????文件???????1502??2007-12-19?16:46??P2P--多用戶在線聊天室(Java源碼)\源碼包\server\ServerConn.java
?????文件???????5020??2007-12-19?20:23??P2P--多用戶在線聊天室(Java源碼)\源碼包\server\SimpleServer.class
?????文件???????5214??2007-12-19?16:46??P2P--多用戶在線聊天室(Java源碼)\源碼包\server\SimpleServer.java
?????文件????????685??2007-12-19?20:23??P2P--多用戶在線聊天室(Java源碼)\源碼包\server\SimpleServer_button1_actionAdapter.class
?????文件????????685??2007-12-19?20:23??P2P--多用戶在線聊天室(Java源碼)\源碼包\server\SimpleServer_button2_actionAdapter.class
?????文件???????2179??2007-12-19?20:23??P2P--多用戶在線聊天室(Java源碼)\源碼包\server\UserThread.class
?????文件???????1893??2007-12-19?16:46??P2P--多用戶在線聊天室(Java源碼)\源碼包\server\UserThread.java
?????目錄??????????0??2007-12-24?11:16??P2P--多用戶在線聊天室(Java源碼)\源碼包\client
?????目錄??????????0??2007-12-24?11:16??P2P--多用戶在線聊天室(Java源碼)\源碼包\server
?????目錄??????????0??2007-12-24?11:16??P2P--多用戶在線聊天室(Java源碼)\源碼包
?????目錄??????????0??2008-09-23?15:28??P2P--多用戶在線聊天室(Java源碼)
-----------?---------??----------?-----??----
???????????????197594????????????????????21
評論
共有 條評論