freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

基于java實(shí)現(xiàn)聊天室范文-資料下載頁

2024-11-17 21:54本頁面

【導(dǎo)讀】基于JAVA實(shí)現(xiàn)聊天室。摘要隨著時(shí)代的發(fā)展時(shí)間信息兩個概念顯得越來越突出在第一時(shí)間掌握第。一手資料是打敗對手取得成功的秘訣伴隨著計(jì)算機(jī)網(wǎng)絡(luò)技術(shù)的迅速發(fā)展通信業(yè)。也蒸蒸日上現(xiàn)在個人電腦已普及到各個家庭單位中為了能實(shí)時(shí)準(zhǔn)確地實(shí)現(xiàn)與朋。友親人同事之間的聯(lián)系網(wǎng)絡(luò)聊天是一種比較經(jīng)濟(jì)實(shí)惠的途徑其發(fā)展前景可觀。本系統(tǒng)利用Java中的socket網(wǎng)絡(luò)編程和多線程技術(shù)實(shí)現(xiàn)主要包括登陸連接。服務(wù)器管理客戶聊天三大功能管理員和用戶經(jīng)過登陸界面分別進(jìn)入到服務(wù)器端。和客戶端客戶通過socket連接服務(wù)器服務(wù)器通過多線程技術(shù)轉(zhuǎn)發(fā)信息到其他客。戶端這種服務(wù)器集中轉(zhuǎn)發(fā)信息的優(yōu)點(diǎn)是通信穩(wěn)定缺點(diǎn)是增加了服務(wù)器端的負(fù)擔(dān)。傳統(tǒng)的面對面之間的交流由于受地域和時(shí)間的影響已經(jīng)滿足不了當(dāng)今社會。的需求利用聊天室這種影響將會降到最小人與人之間的交流將會更加方便快捷。使用Java開發(fā)網(wǎng)絡(luò)程序在網(wǎng)絡(luò)飛速發(fā)展的今天已經(jīng)顯得格外重要與使用其。隨著網(wǎng)絡(luò)技術(shù)的發(fā)展和普及Inter已經(jīng)成為人們獲取有關(guān)信息和相互交

  

【正文】 rver chatFrame thischatFrame chatFrame public void windowClosing WindowEvent e exit program chatFrameexit reference to the method exit in ChatRoomServer import Javaawt import Javaawtevent import Javaio import Java public class ChatRoomClient extends Frame implements Runnable Panel panel1panel2 Button button1button2 TextField textField1textField2 Label label1 TextArea textArea ScrollPane sPanel PrintWriter out BufferedReader in null Socket sock public final static int DEFAULT_PORT 6666 create Thread to Read information from Server Thread readThread boolean isTrue truethread can go on runing public ChatRoomClient try jbInit catch Exception e eprintStackTrace public static void main String[] args main method ChatRoomClient c new ChatRoomClient cshow private void jbInit should set sizeposition and Font of every ponent button1 new Button 連接 set Font button2 new Button 發(fā)送 textField1 new TextField input Server address here textField2 new TextField input Message here and send to Server label1 new Label 消息 panel1 new Panel panel2 new Panel sPanel new ScrollPane textArea new TextArea panel1 press button1 連接 to connect the Client to Server button1addActionListener new JavaawteventActionListener public void actionPerformed ActionEvent e button1_actionPerformed e textField1for input the address of Serverbe registered to KeyListener press keyEnter to connect the Client to Server textField1addKeyListener new textField1_KeyAdapter this JavaawteventKeyAdapter panel1add button1 panel1add textField1 sPanel ScrollPane sPaneladd textArea panel2 press button2 發(fā)送 to send message button2addActionListener new JavaawteventActionListener public void actionPerformed ActionEvent e button2_actionPerformed e textField2for input messagebe registered to KeyListener press keyEnter to send message textField2addKeyListener new textField2_KeyAdapter this panel2add label1 panel2add textField2 panel2add button2 frame thisaddWindowListener new ChatFrame_WindowAdapter this frame is registered to WindowListener thissetLayout new BorderLayout thissetSize 500400 thisadd panel1BorderLayoutNORTH thisadd sPanelBorderLayoutCENTER thisadd panel2BorderLayoutSOUTH thisshow public void startConnect 開始連接 try sock new Socket textField1getText DEFAULT_PORT if sock null connection successed processMsg Connect successfully in new BufferedReader new InputStreamReader sockgetInputStream out new PrintWriter sockgetOutputStream catch IOException ex processMsg extoString processMsg Connect failed readThread new Thread this readThreadstart public void endConnect close IOstream public void sendInformation outprintln textField2getText outflush private void button1_actionPerformed ActionEvent e 連接按鈕 startConnect private void button2_actionPerformed ActionEvent e 發(fā)送按鈕 sendInformation public void stopRun to stop the running thread isTrue false public void processMsg String msg 客戶端處理消息 textAreaappend msg textAreaappend \n public void run String msg isTrue true while isTrue try msg inreadLine if msgequals Server exit Server exit processMsg msg stopRun 終止線程 else if msg null processMsg msg Threadsleep 1000 catch IOException e processMsg etoString catch InterruptedException ei processMsg eitoString endConnect try 服務(wù)器退出關(guān)閉連接和相關(guān)的 流 sockclose inclose outclose catch IOException ioe public void exit 窗口 關(guān)閉如果有連接則關(guān)閉連接和相關(guān)的 流 try send Client exit to Server outprintln Client exit outflush catch Exception exc endConnect try close IOstream sockclose inclose outclose catch IOException ioe finally Systemexit 0 文本筐 textField1 的鍵擊事件適配器 class textField1_KeyAdapter extends JavaawteventKeyAdapter ChatRoomClient chatFrame public textField1_KeyAdapter ChatRoomClient chatFrame thischatFrame chatFrame public void keyPressed KeyEvent e 輸入的是 enter 開始連接 int j egetKeyCode if j eVK_ENTER chatFramestartConnect 文本筐 textField2 的鍵擊事件適配器 class textField2_KeyAdapter extends JavaawteventKeyAdapter ChatRoomClient chatFrame public textField2_KeyAdapter ChatRoomClient chatFrame thischatFrame chatFrame public void keyPressed KeyEvent e 鍵擊 Enter 鍵發(fā)送信息 int j egetKeyCode if j eVK_ENTER chatFramesendInformation 窗口關(guān)閉事件適配器 class ChatFrame_WindowAdapter extends JavaawteventWindowAdapter ChatRoomClient chatFrame public ChatFrame_WindowAdapter ChatRoomClient chatFrame thischatFrame chatFrame public void windowClosing WindowEvent e exit program chatFrameexit reference to the method exit in ChatRoomClien
點(diǎn)擊復(fù)制文檔內(nèi)容
環(huán)評公示相關(guān)推薦
文庫吧 www.dybbs8.com
備案圖鄂ICP備17016276號-1