【正文】
){ = allFriends。 (getJContentPane())。 } return jContentPane。 (new Rectangle(2, 2, 200, 376))。 ().add(new TalkWindowInfo(tw,ALL))。i++){ if(().get(i).getTargetUserInfo().equals(id)){ return true。 } //初始化好友樹的方法 public DefaultMutableTreeNode initTree(){ DefaultMutableTreeNode root = new DefaultMutableTreeNode (好友列表(+me+))。 TalkingMainTreeInfo treeNodeInfo = new TalkingMainTreeInfo((i),friend)。 private JTextField jTextField = null。// 連接服務(wù)器端的輸出流 // 準(zhǔn)備傳送的文件 private File readyforsendfile。 i++) { if (().get(i).getTalkingWindow() .equals(this)) { ().remove(i)。 } public TalkWindow(String me, String target, LinkInfo linkInfo) { ().setVisible(true)。 } } /** * This method initializes jFrame * * return */ private JFrame getJFrame() { if (jFrame == null) { jFrame = new JFrame()。 } return jFrame。 } return jContentPane。 } return jPanel。 (發(fā)送文件)。 ((), out)。 i++) { if (().get(i).equals(target)) { friendOnline = true。 (() + 我說:\n + () + \n)。 ().setValue( ().getMaximum())。 (from, out)。 i++) { Component t = (i)。 byte[] buf = new byte[1024]。 (buf,0,loaded)。 } catch (Exception e) { ()。 FileInputStream fis = new FileInputStream( readyforsendfile)。 (true)。 File f = ()。 public Server(){ users = new HashMapString,UserInfo()。 ()。 int mand = 1。 sendMessageToAll()。 break。 } finally{ //從共享中刪除當(dāng)前用戶 (())。 break。 //請求個人傳送文件 case : (message:請求傳送文件至私人)。 break。 } //線程體 public void run() { try { //獲取當(dāng)前連接客戶端的輸入流,用于獲取來自客戶端的信息 in = ()。 } } catch (IOException e) { ()。 (請求發(fā)送完畢)。 } } // 傳送文件請求 public void sendFile() { JFileChooser fd = new JFileChooser()。\n)。 (target, out)。\n)。 ().setValue( ().getMaximum())。 long len = (in)。 for (int i = 0。 readyforgetFile = ()。 ().setValue( ().getMaximum())。 (target, out)。// 當(dāng)前聊天對象是否在線 for (int i = 0。 return false。 } /** * This method initializes jButton * * return */ private JButton getJButton() { if (jButton == null) { jButton = new JButton()。 (true)。 (null)。 removeTalkWindowInfo()。 } try { out = ().getOutputStream()。 (false)。 } // 關(guān)閉窗口的同時刪除聊天窗口信息 public void closeFrameAndClearTalkWindowInfo() { for (int i = 0。 private String target。 // jve:declindex=0:visualconstraint=168,56 private JPanel jContentPane = null。i++){ //不將自己放在好友列表上 if((i).equals(me)){ continue。i++){ if(((i).getDmtn())){ return (i).getUserInfo()。 } for(int i =0。 //} return jTree。 } return jButtonFind。 (getJButtonFind(), null)。 (Talking)。 = linkInfo。 private JScrollPane jScrollPane = null。 (, out)。!().equals()){ if(!().equals(())){ ().showAlert(兩次密碼輸入不一致)。!().equals()amp。 (去登陸)。 } /** * This method initializes jButtonReg * * return */ private JButton getJButtonReg() { if (jButtonReg == null) { jButtonReg = new JButton()。 (new Rectangle(110, 34, 258, 41))。 (jLabelRegRepassword, null)。 jLabelRegUserName = new JLabel()。 } /** * This method initializes jContentPane * * return */ private JPanel getJContentPane() { if (jContentPane == null) { jLabelRegRepassword = new JLabel()。 } /** * This method initializes jFrame * * return */ private JFrame getJFrame() { if (jFrame == null) { jFrame = new JFrame()。 private OutputStream out。 private JLabel jLabelRegPassword = null。 (去注冊)。 //設(shè)置LinkInfo中自己的信息 (())。amp。 (登陸)。 } return jTextFieldLoginUserName。 (getJTextFieldLoginPassword(), null)。 (new Rectangle(18, 53, 335, 38))。 (new () { public void windowClosing( e) { (0)。 ().setVisible(true)。 private JPasswordField jTextFieldLoginPassword = null。 為了讓我們更好的了解和設(shè)計(jì)多人聊天室這個軟件,也更好的開發(fā)和維護(hù)這個軟件,我們根據(jù)客戶端和服務(wù)器端的功能模塊之間的邏輯關(guān)系給出了一個流程圖,這個流程圖主要是分為服務(wù)器端和客戶端兩個部分,服務(wù)器端我們從建立ServerSoket端口號開始進(jìn)行解析,到線程死亡結(jié)束,客戶端我們從登陸界面開始到用戶關(guān)閉聊天窗口結(jié)束。反之則會彈出提示用戶昵稱或者用戶密碼輸入錯誤,提示用戶重新輸入用戶信息。在Servlet方面,我們首先通過Socket建立服務(wù)器和客戶端之間的連接,創(chuàng)建Soket實(shí)例,使用ServletSoket監(jiān)聽端口,獲取用戶狀態(tài)以及用戶的網(wǎng)絡(luò)發(fā)送請求和應(yīng)答請求,在本文并沒有過多實(shí)現(xiàn)服務(wù)器端的功能,所以服務(wù)器端只是一個文件和數(shù)據(jù)的中轉(zhuǎn)站和傳輸站。Window該類的讀寫是基于指針的操作。缺點(diǎn):不易維護(hù),B/S結(jié)構(gòu)的優(yōu)點(diǎn):易于維護(hù),缺點(diǎn):效果差,交互性不強(qiáng)。這7層是:物理層、數(shù)據(jù)鏈路層、網(wǎng)路層、傳輸層、話路層、表示層和應(yīng)用層。線程是并發(fā)運(yùn)行的,操作系統(tǒng)將運(yùn)行時間分為若干個時間片段,盡可能均勻的分配給每一個任務(wù),被分配時間片段之后,任務(wù)就有可能CPU所執(zhí)行,從微觀上來講,每個任務(wù)都是走走停停,但是隨著任務(wù)的執(zhí)行宏觀上來看就是所有任務(wù)都在執(zhí)行,這種都運(yùn)行的現(xiàn)象就稱之為并發(fā),但絕對不是真正意義上的“同時發(fā)生”。在現(xiàn)實(shí)生活中我們有多種手段和親戚朋友溝通交流和通訊,但要么是實(shí)時性不強(qiáng)或則是費(fèi)用太高、功能單一無法做到網(wǎng)絡(luò)聊天工具的多樣性功能,能夠同時與多個好友進(jìn)行通訊,這無疑填補(bǔ)了我們生活方式的空白,而網(wǎng)絡(luò)聊天軟件的使用方便快捷、系統(tǒng)占用消耗資源少等諸多優(yōu)點(diǎn),都讓他快速成為了企業(yè)事業(yè)單位和個人廣泛應(yīng)用的軟件之一。 C / S structure。更加關(guān)鍵的是網(wǎng)絡(luò)工具給我們提供了一個低消費(fèi)更便于交流溝通的平臺,這個網(wǎng)絡(luò)工具平臺擁有廣泛性、即時性、便捷性,因而得到了廣大公司、事業(yè)單位、院校和民眾的認(rèn)可,本論文敘述的是一種基于利用TCP/IP協(xié)議的、利用數(shù)據(jù)流的存儲和讀取、C/S框架結(jié)構(gòu)模式、多線程、實(shí)現(xiàn)設(shè)計(jì)點(diǎn)對點(diǎn)和點(diǎn)對面通信的一個多人網(wǎng)絡(luò)連天工具,可以進(jìn)行私聊、群聊、文件傳輸?shù)?關(guān)鍵詞:Java;聊天室;線程;協(xié)議;數(shù)據(jù)流;C/S結(jié)構(gòu);AbstractWith the advent of the information revolution, using networking tools to municate one thing has bee indispensable in our daily life are inseparable from the parison with the use of mobile munications and text messaging munication, they are too cumbersome and costly, and online munication tools due to ease of use, instant transfer of information, especially the many young people to the pursuit and use. More critical is networking tools provides us with a low consumption easier munication platform, the network platform has extensive tools, immediacy, convenience, and therefore get the majority of panies, institutions, universities and public recognition, this paper describes is based on the use of TCP / IP protocol, the use of storage and reading of data flow, C / S frame mode, multithreaded, to implement a multiplayer online groaning tool design point and point opposite the