《計算機網(wǎng)絡通信 》課程設計報告.doc_第1頁
《計算機網(wǎng)絡通信 》課程設計報告.doc_第2頁
《計算機網(wǎng)絡通信 》課程設計報告.doc_第3頁
《計算機網(wǎng)絡通信 》課程設計報告.doc_第4頁
《計算機網(wǎng)絡通信 》課程設計報告.doc_第5頁
免費預覽已結束,剩余34頁可下載查看

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

計算機網(wǎng)絡通信課程設計課程設計 設計題目 聊天程序 課程編號 1610033 學生姓名李財錫 劉偉鎮(zhèn) 黃小敏 巫秋燕 學 號 所在專業(yè)計算機網(wǎng)絡技術 所在班級084 指導教師劉思鳳 成績 設計時間 1 月 4 日至 2010 年 1 月 8 日 目 錄 目目 錄錄 采用了 WORD 的目錄功能 請同學查閱 WORD 的標題和目錄使用方法 以便正確 生成目錄 模板中的分頁符也不得隨意刪除 以免造成頁眉和頁碼的錯誤 設計總說明 1 設計總說明 I 1系統(tǒng)功能介紹系統(tǒng)功能介紹 1 1 11 1建立偵聽服務 建立偵聽服務 1 1 21 2 用戶登錄用戶登錄 1 1 3 收發(fā)聊天信息 1 41 4收發(fā)系統(tǒng)消息收發(fā)系統(tǒng)消息 3 1 51 5 用戶下線和通知用戶下線和通知 3 1 6服務關閉服務關閉 3 2 代碼實現(xiàn)代碼實現(xiàn) 3 2 1 用戶信息鏈表實現(xiàn) 2 2服務器主框類架的服務器主框類架的實現(xiàn)實現(xiàn) 5 2 3 服務器偵聽線程類的實現(xiàn)服務器偵聽線程類的實現(xiàn) 6 2 42 4服務器接收線程類的實現(xiàn)服務器接收線程類的實現(xiàn) 6 2 5 客戶端主框類的客戶端主框類的實現(xiàn)實現(xiàn) 7 2 6 客戶端接收線程類的實現(xiàn) 3附 源程序附 源程序 8 參考文獻 9 I 設計總說明 這里主要用了 java 的網(wǎng)絡編程相關知識 通過學習了解了 TCP 和 UDP 協(xié)議的基本 知識和 Socket 編程的基本概念 以及 TCP 協(xié)議的響應流程 現(xiàn)在通過使用 java 提供 的流 Socket 和數(shù)據(jù)包 Socket 利用流 Socket 和數(shù)據(jù)包 Socket 建立通信連接 最后實 現(xiàn)了一個完整的聊天程序 該聊天系統(tǒng)是基于 TCP 協(xié)議的流 Socket 實現(xiàn)的 它采用了 典型的 C S 架構 包括一個服務器應用程序和一個客戶端程序 可以同時供多個用戶 進行聊天 課程設計要求 1 登錄功能 客戶端登錄到聊天服務器 服務器管理所有登錄的客戶 并將客戶列 表發(fā)送給各個客戶顯示 2 客戶可以通過服務器轉發(fā) 實現(xiàn)一對一和多對多聊天 3 實現(xiàn)呼叫功能 當客戶端程序連接服務器時 通過服務器搜索所要呼叫的客戶 如果檢測到此用戶且該用戶正處于聯(lián)網(wǎng)狀態(tài) 則服務器通知此用戶的客戶端程序響應 主叫方客戶端程序 然后在主叫方和被叫方建立連接后 雙方就可以聊天或進行其它 的通信 4 客戶端程序應該可以實時顯示目前其它用戶的狀態(tài) 例如好友信息 上 下線 網(wǎng)絡系統(tǒng)集成課程結業(yè)論文 報告 1 編寫聊天程序 1系統(tǒng)功能介紹系統(tǒng)功能介紹 本程序具有完整的會話功能 采用 C S 結構 由兩部分組成 客戶端和服務器 可 以供多個用戶進行聊天 服務器具有建立偵聽服務 轉發(fā)聊天信息 響應用戶下線 發(fā)送系統(tǒng)消息的功能 要實現(xiàn)這四個功能 需要建立以下四個類 1 用戶信息鏈表 2 服務器主框類 3 服務器偵聽線程類 4 服務器接收線程類 客戶端具有請求登錄 請求下線 發(fā)送聊天信息 接收聊天信息 接收系統(tǒng)信息的 功能 要實現(xiàn)這些功能也要建立兩個類 客戶端主框架類和客戶端接收線程類 下面通過聊天系統(tǒng)的演示來具體了解聊天系統(tǒng)的功能 1 11 1建立偵聽服務 建立偵聽服務 初始狀態(tài)的服務器如圖 1 所示 其主框架上具有兩個按鈕 分別用于啟動和 關閉服務器 點擊 啟動 按鈕處于允許狀態(tài) 點擊 關閉 按鈕處于禁止狀態(tài) 服務器啟 動后 就進入偵聽狀態(tài) 關閉就結束偵聽 這里設計服務在 8000 端口啟動 圖 1 圖 2 1 21 2 用戶登錄用戶登錄 用戶登錄過程其實就是客服端請求登錄和服務器響應登錄兩個過程 初始狀態(tài)的 網(wǎng)絡系統(tǒng)集成課程結業(yè)論文 報告 2 客戶端如圖 3 它的 上線 按鈕用于用戶登錄 下線 按鈕用于用戶下線 界面 下方的 JTextField 控件 在用戶未登錄時輸入用戶名稱 在用戶登錄后用于輸入聊天信 息 并按回車確定操作 圖 3 1 3收發(fā)聊天信息收發(fā)聊天信息 這個過程包含了客戶端發(fā)送聊天信息和服務器轉發(fā)聊天信息 當客戶端登錄后與 其他在線用戶進行聊天 只要在界面最底部的 JTextField 控件中輸入聊天信息 按回車 鍵就可以發(fā)送出去了 而那兩個 JComboBox 控件分別用來選擇聊天信息的對象和發(fā)送 聊天信息的表情動作 悄悄話 復選框用來標識此信息是否轉發(fā)給非目標對象的其他 在線用戶 1 41 4收發(fā)系統(tǒng)消息收發(fā)系統(tǒng)消息 系統(tǒng)信息的收發(fā)是單方面的 只能有服務器發(fā)給客戶端 在服務器主界面輸入 系統(tǒng)信息 按回車鍵 系統(tǒng)就會將信息發(fā)送到所有客戶端 客戶端收到信息后 網(wǎng)絡系統(tǒng)集成課程結業(yè)論文 報告 3 就會顯示在界面上 如下圖 1 51 5用戶下線和通知用戶下線和通知 用戶下線與用戶登錄一樣 要涉及到客戶端請求下線和服務器響應請求兩個過程 用戶單擊客戶端 下線 按鈕 客戶端就會向服務器發(fā)送下線請求 服務器接收 后就胡釋放與該用戶的相關資源 并向其他用戶發(fā)送該用戶下線通知以及更新在線用 戶列表 如下圖 網(wǎng)絡系統(tǒng)集成課程結業(yè)論文 報告 4 1 6 服務關閉服務關閉 當服務器關閉服務時 就向所有在線用戶發(fā)送服務器關閉信息 并且關閉所有與 在線用戶相連接的輸入輸出流和套接字 將且將界面調整到最初狀態(tài) 如圖 客服端接收到服務器的關閉信息時 它將在界面上顯示服務器關閉的提示信息 并且關閉與服務相連的輸入輸出流和套接字 刪除在線用戶列表 將界面調整到最初 狀態(tài) 2 代碼實現(xiàn)代碼實現(xiàn) 2 1用戶信息鏈表的實現(xiàn)用戶信息鏈表的實現(xiàn) 用戶信息鏈表類 UserInfoList 需要對實現(xiàn)對用戶信息的添加 刪除和查詢功能 在實現(xiàn) UserInfoList 類之前 先定義一個用于描述單個用戶信息的數(shù)據(jù)結構 Node 類 并定義五個數(shù)據(jù)成員 用戶昵稱 套接字 輸入流 輸出流和 Next 指針 public class Node String username null 用戶昵稱 Socket socket null 套接字 ObjectOutputStream output null 輸出流 ObjectInputStream input null 輸入流 Node next null 保存鏈表中下一個節(jié)點的指針 在UserInfoList 的構造函數(shù)中 對 UserInfoList 的成員變量進行初始化 public UserInfoList root new Node root next null 創(chuàng)建鏈表的節(jié)點 pointer null count 0 為UserInfoList類添加成員函數(shù)add完成用戶信息節(jié)點的添加功能 public void add Node n pointer root 將游標指向根節(jié)點 網(wǎng)絡系統(tǒng)集成課程結業(yè)論文 報告 5 while pointer next null 判斷是否鏈表尾部 pointer pointer next 將游標后移 pointer next n 加入節(jié)點 n next null count 計數(shù)器加一 為UserInfoList類添加成員函數(shù)del 完成用戶信息節(jié)點的刪除功能 public void del Node n pointer root 將游標指向根節(jié)點 while pointer next null 判斷是否鏈表尾部 if pointer next n 判斷當前節(jié)點是否為要刪除節(jié)點 pointer next n next 刪除節(jié)點 count 計數(shù)器減一 break pointer pointer next 將游標指向下一節(jié)點 為UserInfoList類添加成員函數(shù)getCount 提供返回鏈表中元素個數(shù)的功能 public int getCount return count 返回當前鏈表中元素的個數(shù) 為UserInfoList類添加成員函數(shù)find 完成在用戶信息鏈表中查找指定元素的功能 為方 便起見 定義兩個find函數(shù) 入口參數(shù)分別為String和int public Node find String username if count 0 return null pointer root while pointer next null pointer pointer next if pointer username equalsIgnoreCase username return pointer return null public Node find int index if count 0 return null if index 0 return null 網(wǎng)絡系統(tǒng)集成課程結業(yè)論文 報告 6 pointer root int i 0 while i index 1 if pointer next null pointer pointer next else return null i return pointer 2 2 服務器主框類架的實現(xiàn)服務器主框類架的實現(xiàn) 服務器主框類架類需要實現(xiàn)人機交互功能 啟動服務功能 關閉服務功能和發(fā)送系統(tǒng)信息功能 需要為工程添加服務器主框類 名命為 ServerFrame 在 ServerFrame 類的構造函數(shù)中 完成為服務器控件的添加 控件位置 的調整 控件的初始狀態(tài)的設定及控件事件偵聽函數(shù)的添加 添加函數(shù) init 在其中完 成界面的初始化功能 在 init 函數(shù)中 除對事件進行添加和調整外 還對控件添加事 件偵聽器 如為關閉服務按鈕添加偵聽器 jbStopServer addActionListener new ActionListener public void actionPerformed ActionEvent e stopServer 在 ServerFrame 中添加 starrServer 函數(shù)完成啟動服務的功能 添加 stopServer 函數(shù)完成 關閉服務的功能 添加 sendStopToAll 函數(shù)依次向所有在線用戶發(fā)送服務器關閉消息 添加 sendSystemMessage 函數(shù)實現(xiàn)發(fā)送系統(tǒng)消息的功能 添加 sendMsgToAll 函數(shù)完成 向所有在線用戶發(fā)送系統(tǒng)消息的功能 2 3服務器偵聽線程類的實現(xiàn)服務器偵聽線程類的實現(xiàn) 服務器偵聽線程類需要偵聽客戶端的登錄請求 并且為該用戶啟動專用線程 處理 與此用戶相關的操作 首先為工程添加 ServerListenThread 類 繼承其父類 Thread 在 這個類中實現(xiàn)偵聽客戶端連接 并響應用戶登錄的功能 在這個類中最重要的功能是 網(wǎng)絡系統(tǒng)集成課程結業(yè)論文 報告 7 在 run 函數(shù)中實現(xiàn)的 當服務器啟動時 就會建立偵聽線程 并且調用 start 函數(shù)開始 運行線程 public void run 服務器偵聽線程的執(zhí)行體 while isStop 創(chuàng)建用戶信息節(jié)點 client socket server accept 偵聽客戶端連接 client output newObjectOutputStream client socket getOutputStream client output flush 得到套接字輸入輸出流 client input newObjectInputStream client socket getInputStream client username String client input readObject combobox addItem client username 讀取用戶昵稱 userInfoList add client textarea append user client username 上線 n 顯示提示信息 textfield setText 在線用戶 userInfoList getCount 人 n recvThread new ServerReceiveThread textarea textfield combobox client userInfoList recvThread start 啟動線程 2 42 4服務器接收線程類的實現(xiàn)服務器接收線程類的實現(xiàn) 服務器接收線程類需要接收客戶端發(fā)來的信息 并且對該信息進行分析 執(zhí)行 相應操作 當服務器收到客戶端發(fā)來的聊天信息 對發(fā)送對象進行判斷 如果發(fā)送 對象是所有用戶 則將信息發(fā)給所有用戶 同理 如果是特定用戶就發(fā)給特定用戶 當服務器接收到客戶端發(fā)來的下線請求時 就關閉所有與該用戶相關的輸入輸出流 和套接字 并將該用戶從在線列表中刪除 此外 還需向所有在線用戶發(fā)送該用戶 下線的通知和重發(fā)最新的列表 首先為工程添加新類 命名為ServerReceiveThread 實現(xiàn)接收客戶端信息的功能 方法和偵聽線程差不多 它的成員函數(shù)sendToAll實現(xiàn)向所有在線用戶轉發(fā)聊天信息 的功能 另一個成員函數(shù)sendUserList實現(xiàn)向所有在線用戶發(fā)送用戶列表的功能 public void sendToAll String msg int count userInfoList getCount int i 0 while i count Node node userInfoList find i 網(wǎng)絡系統(tǒng)集成課程結業(yè)論文 報告 8 if node null i continue try node output writeObject 聊天信息 node output flush node output writeObject msg node output flush 2 5客戶端主框類的實現(xiàn)客戶端主框類的實現(xiàn) 客戶端主框架類實現(xiàn)了人機交互 用戶登錄 用戶下線和聊天信息的發(fā)送功能 客戶端的主框架類為 ClientFrame 其構造函數(shù)完成為客戶端控件的添加 控件位置的 調整 控件初始狀態(tài)的設定以及控件事件偵聽函數(shù)的添加 成員函數(shù) LogIn 完成用戶 登錄功能 LogOut 完成用戶下線功能 SendMessage 用于發(fā)送聊天信息 public void SendMessage String toSomebody combobox getSelectedItem toString String status if checkbox isSelected status 悄悄話 String action actionlist getSelectedItem toString String message textfield getText if socket isClosed return try output writeObject 聊天信息 發(fā)送聊天信息標識 output flush output writeObject toSomebody 發(fā)送聊天對象 output flush output writeObject status 發(fā)送聊天狀態(tài) output flush output writeObject action 發(fā)送聊天表情 output flush output writeObject message 發(fā)送聊天信息內容 output flush 網(wǎng)絡系統(tǒng)集成課程結業(yè)論文 報告 9 2 62 6客戶端接收線程類的實現(xiàn)客戶端接收線程類的實現(xiàn) 客戶端接收線程類需要接收服務器發(fā)來的信息 并對該信息進行分析 執(zhí)行相應 的操作 客戶端收到的服務器信息有三種 聊天信息和系統(tǒng)信息 用戶列表信息 服務關閉信息 客戶端將接收到聊天信息和系統(tǒng)信息顯示在界面上 接收到用戶信息 就對信息進行分析 獲取在線用戶列表 顯示在界面組合框中 接收到關閉信息 則 執(zhí)行關閉操作 命名客戶端接收線程類為 ClientReceiveThread 實現(xiàn)接收服務器信息的功能 主 要在 run 函數(shù)中實現(xiàn)該類的功能 public void run 線程執(zhí)行體 sendUserList while isStop 讀取服務器發(fā)送的聊天信息 if type equalsIgnoreCase 聊天信息 處理聊天信息 String toSomebody String client input readObject 獲取系統(tǒng)信息內容 String status String client input readObject String action String client input readObject String message String client input readObject String msg client username action 對 toSomebody 說 message n 顯示信息 3附 源程序附 源程序 附 錄 10 參考文獻 Java 語言與面向對象程序設計 Java 編程案例解析 計算機網(wǎng)絡通信教程 附 錄 附 錄 11 宋體小四號 1 25 倍行距 要求 附錄的有無根據(jù)情況需要而定 內容一般包 括正文內不便列出的冗長公式推導 符號說明 含縮寫 計算機程序 圖紙 表格等 附錄中有程序源代碼的因篇幅限制可酌情考慮內容的字號 用戶信息鏈表類 import import java io public class Node String username null Socket socket null ObjectOutputStream output null ObjectInputStream input null Node next null import javax swing import import java io public class UserInfoList Node root Node pointer int count public UserInfoList root new Node root next null pointer null count 0 public void add Node n pointer root 附 錄 12 while pointer next null pointer pointer next pointer next n n next null count public void del Node n pointer root while pointer next null if pointer next n pointer next n next count break pointer pointer next public int getCount return count public Node find String username if count 0 return null pointer root while pointer next null pointer pointer next if pointer username equalsIgnoreCase username 附 錄 13 return pointer return null public Node find int index if count 0 return null if index 0 return null pointer root int i 0 while i index 1 if pointer next null pointer pointer next else return null i return pointer 服務端主框架類 import java awt import java awt event 附 錄 14 import javax swing import javax swing event import javax swing border import java io import public class ServerFrame extends JFrame private JButton jbStartServer private JButton jbStopServer private JButton b1 private JScrollPane js private Border border private ServerSocket serverSocket private JComboBox combobox private JTextArea textarea private JTextField textfield private JTextField systemMsg private UserInfoList userInfoList private ServerListenThread listenThread public ServerFrame super 服務端 init setSize 370 570 show public void init 初始化 Border bevelBorder BorderFactory createBevelBorder BevelBorder RAISED Color white Color white Color white Color white Border emptyBorder BorderFactory createEmptyBorder 1 1 1 1 border BorderFactory createCompoundBorder bevelBorder emptyBorder jbStartServer new JButton 啟動 jbStopServer new JButton 關閉 附 錄 15 b1 new JButton 發(fā)送 jbStopServer setEnabled false jbStartServer addActionListener new ActionListener public void actionPerformed ActionEvent e startServer jbStopServer addActionListener new ActionListener public void actionPerformed ActionEvent e stopServer combobox new JComboBox combobox insertItemAt 所有人 0 combobox setSelectedIndex 0 textarea new JTextArea 20 20 textarea setEditable false js new JScrollPane textarea textfield new JTextField 40 textfield setEditable false systemMsg new JTextField 40 systemMsg setEnabled false systemMsg addActionListener new ActionListener 附 錄 16 public void actionPerformed ActionEvent e sendSystemMessage this addWindowListener new WindowAdapter public void windowClosing WindowEvent e stopServer System exit 0 Container c getContentPane c setLayout null jbStartServer setBorder border jbStartServer setBounds 30 30 90 30 jbStopServer setBorder border jbStopServer setBounds 150 30 90 30 textfield setBounds 30 75 100 20 js setBounds 30 110 300 300 combobox setBounds 30 425 90 30 systemMsg setBounds 30 470 200 50 b1 setBounds 250 470 60 50 c add b1 null c add jbStartServer null c add jbStopServer null c add textfield null c add js null c add combobox null 附 錄 17 c add systemMsg null public void startServer 啟動服務 try serverSocket new ServerSocket 8000 10 textarea append 服務在 8000 端口啟動 n jbStartServer setEnabled false jbStopServer setEnabled true systemMsg setEnabled true catch Exception e userInfoList new UserInfoList listenThread new ServerListenThread serverSocket combobox textarea textfield userInfoList listenThread start public void stopServer 實現(xiàn)關閉服務功能 try sendStopToAll 向所有在線用戶發(fā)送關閉信息 listenThread isStop true serverSocket close int count userInfoList getCount 附 錄 18 int i 0 while i count Node node userInfoList find i node input close node output close node socket close i jbStartServer setEnabled true jbStopServer setEnabled false systemMsg setEnabled false combobox removeAllItems combobox addItem 所有人 catch Exception e public void sendStopToAll 向所有在線用戶發(fā)送服務關閉消息 int count userInfoList getCount int i 0 while i count Node node userInfoList find i if node null i continue try 附 錄 19 node output writeObject 服務關閉 node output flush catch Exception e i public void sendSystemMessage 實現(xiàn)發(fā)送系統(tǒng)消息功能 String toSomebody combobox getSelectedItem toString String message systemMsg getText if toSomebody equalsIgnoreCase 所有人 sendMsgToAll message n else Node node userInfoList find toSomebody try node output writeObject 系統(tǒng)信息 node output flush node output writeObject message n node output flush catch Exception e 附 錄 20 public void sendMsgToAll String msg int count userInfoList getCount int i 0 while i count Node node userInfoList find i if node null i continue try node output writeObject 系統(tǒng)信息 node output flush node output writeObject msg node output flush catch Exception e i public static void main String args new ServerFrame 服務器偵聽線程類 import java awt 附 錄 21 import java awt event import javax swing import javax swing event import java io import public class ServerListenThread extends Thread ServerSocket server JComboBox combobox JTextArea textarea JTextField textfield UserInfoList userInfoList Node client ServerReceiveThread recvThread public boolean isStop public ServerListenThread ServerSocket server JComboBox combobox JTextArea textarea JTextField textfield UserInfoList userInfoList this server server bobox combobox this textarea textarea this textfield textfield this userInfoList userInfoList isStop false 附 錄 22 public void run while isStop client socket server accept client output new ObjectOutputStream client socket getOutputStream client output flush client input new ObjectInputStream client socket getInputStream client username String client input readObject combobox addItem client username userInfoList add client textarea append user client username 上線 n textfield setText 在線用戶 userInfoList getCount 人 n recvThread new ServerReceiveThread textarea textfield combobox client userInfoList recvThread start catch Exception e 服務器接收線程類 import javax swing 附 錄 23 import java io import public class ServerReceiveThread extends Thread JTextArea textarea JTextField textfield JComboBox combobox Node client UserInfoList userInfoList public boolean isStop public ServerReceiveThread JTextArea textarea JTextField textfield JComboBox combobox Node client UserInfoList userInfoList this textarea textarea this textfield textfield this client client this userInfoList userInfoList bobox combobox isStop false public void run sendUserList while isStop 附 錄 24 if type equalsIgnoreCase 聊天信息 String toSomebody String client input readObject String status String client input readObject String action String client input readObject String message String client input readObject String msg client username action 對 toSomebody 說 message n if status equalsIgnoreCase 悄悄話 msg 悄悄話 msg textarea append msg if toSomebody equalsIgnoreCase 所有人 sendToAll msg else try client output writeObject 聊天信息 client output flush client output writeObject msg client output flush catch Exception e Node node userInfoList find toSomebody if node null 附 錄 25 node output writeObject 聊天信息 node output flush node output writeObject msg node output flush else if type equalsIgnoreCase 用戶下線 Node node userInfoList find client username userInfoList del node String msg 用戶 client username 下線 n int count userInfoList getCount combobox removeAllItems combobox addItem 所有人 int i 0 while i count node userInfoList find i if node null i continue combobox addItem node username i combobox setSelectedIndex 0 textarea append msg textfield setText 在線用戶 userInfoList getCount 人 n sendToAll msg sendUserList 附 錄 26 break catch Exception e public void sendToAll String msg int count userInfoList getCount int i 0 while i count Node node userInfoList find i if node null i continue try node output writeObject 聊天信息 node output flush node output writeObject msg node output flush catch Exception e i 附 錄 27 public void sendUserList String userlist int count userInfoList getCount int i 0 while i count Node node userInfoList find i if node null i continue userlist node username userlist n i i 0 while i count Node node userInfoList find i if node null i continue try node output writeObject 用戶列表 node output flush node output writeObject userlist node output flush 附 錄 28 catch Exception e i 客戶端主框架類 import java awt import java awt event import javax swing import javax swing event import javax swing border import java io import public class ClientFrame extends JFrame private JComboBox combobox private JTextArea textarea private JTextField textfield private JCheckBox checkbox private JComboBox actionlist private JButton login private JButton logout private Border border private JTextField seperater private JScrollPane js private JButton b1 Socket socket ObjectOutputStream output ObjectInputStream input ClientReceiveThread recvThread 附 錄 29 public ClientFrame super 客戶端 Border bevelBorder BorderFactory createBevelBorder BevelBorder RAISED Color white Color white Color white Color white Border emptyBorder BorderFactory createEmptyBorder 1 1 1 1 border BorderFactory createCompoundBorder bevelBorder emptyBorder login new JButton 上線 logout new JButton 下線 b1 new JButton 發(fā)送 logout setEnabled false combobox new JComboBox combobox addItem 所有人 combobox setSelectedIndex 0 textarea new JTextArea 20 20 textarea setEditable false js new JScrollPane textarea textfield new JTextField 請先輸入你的昵稱 再上線 20 seperater new JTextField 20 seperater setEditable false checkbox new JCheckBox 悄悄話 checkbox setSelected false actionlist new JComboBox actionlist addItem 微笑地 actionlist addItem 生氣地 actionlist addItem 小心地 actionlist setSelectedIndex 0 附 錄 30 login setBorder border login setBounds 30 30 90 30 logout setBorder border logout setBounds 150 30 90 30 seperater setBounds 30 75 300 20 js setBounds 30 110 300 300 combobox setBounds 30 425 90 30 actionlist setBounds 150 425 90 30 checkbox setBounds 270 425 90 30 textfield setBounds 30 470 200 50 b1 setBounds 250 470 60 50 Container c getContentPane c setLayout null c add b1 null c add login null c add logout null c add seperater null c add js null c add combobox null c add actionlist null c add checkbox null c add textfield null login addActionListener new ActionListener public void actionPerformed ActionEvent e LogIn logout addActionListener 附 錄 31 new ActionListener public void actionPerformed ActionEvent e LogOut b1 addActionListener new ActionListener public void actionPerformed ActionEvent e SendMessage textfield addActionListener new ActionListener public void actionPerformed ActionEvent e SendMessage this addWindowListener new WindowAdapter public void windowClosing WindowEvent e LogOut System exit 0 setSize 370 570 show 附 錄 32 public void LogIn try socket new Socket 192 168 2 145 8000 注意服務器 IP output new ObjectOutputStream socket getOutputStream output flush input new ObjectInputStream socket getInputStream output writeObject textfield getText output flush recvThread new

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論