




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
課程設(shè)計(jì)之楊若古蘭創(chuàng)作指點(diǎn)教師題目收集聊天室課程設(shè)計(jì)專業(yè)計(jì)算機(jī)科學(xué)與技術(shù)2)電子工業(yè)出版社《JAVA程序設(shè)計(jì)實(shí)用教程》,葉核亞編著三、設(shè)計(jì)完成后提交的文件和圖表2)電子工業(yè)出版社《JAVA程序設(shè)計(jì)實(shí)用教程》,葉核亞編著考材料成績?cè)u(píng)定表目錄私達(dá)D美踐D能力空高偽石忙偽、學(xué)凡於知識(shí)空運(yùn)用才石己匕小τ專τ行測(cè)τ更忙創(chuàng)造Lτ、黃舍付特忙2過間手配Lτ、私達(dá)忙VisualC++D課程D設(shè)計(jì)D美習(xí)己D7了(ⅣD詳L〉說明付VisualC++6.0環(huán)境D下τ、1二D〉7卜吻工アD過程空設(shè)計(jì)Lτ、己D〉7卜吻工ア付各種D虧ー夕D個(gè)數(shù)空統(tǒng)計(jì)L忙Dτ才.己D〉7卜吻工アD機(jī)能付、工ー擴(kuò)ー付1段D文字空入力Lτ、〉7卜吻工ア付文字D中D各類D虧ー夕D數(shù)空記錄Lτ、英文D虧ー夕D數(shù)、數(shù)字D虧ー夕D數(shù)、空欄D虧ー夕D數(shù)匕子扎D夕(了D虧ー夕D數(shù)空含凡τ、子Lτ子扎j空明j小忙示L去才.以下、課程空通Lτ說明空設(shè)計(jì)Lτ、虧ー夕付〉7卜吻工アD說明空統(tǒng)計(jì)Lτ、了口勿方么付說明空調(diào)整Lτ、然括女狀D方面空開凳Lτ、詳L〈己D了口勿方么D剿作D過程空說明Lτ、感化、各種D美行才石己匕小τ專石操縱.八Ψr7了(Ⅳ件、電報(bào)、電話等曾經(jīng)難以滿足人們的交流請(qǐng)求,在互聯(lián)網(wǎng)流方式曾經(jīng)成為必定潮流.是以出現(xiàn)了QQ等聊天工具,然而QQ等聊天工具雖然方便、實(shí)用,但是,文娛功能太多,有很多吸惹人的文娛功能,實(shí)用性的即時(shí)通訊軟件.用戶接收的各種動(dòng)靜.環(huán)境需求分析運(yùn)轉(zhuǎn)環(huán)境:Windows9x、2000、XP、Windows7是客戶端的登陸,客戶端在登陸時(shí),必須設(shè)次要檢測(cè)到有一個(gè)連接請(qǐng)求,那么服務(wù)器就理它的各種請(qǐng)求.對(duì)于客戶端的各種請(qǐng)求,實(shí)際上都是通過在客戶發(fā)往服務(wù)器靜,服務(wù)器便會(huì)根據(jù)其尾部的目的信息,向目標(biāo)端轉(zhuǎn)發(fā)該條動(dòng)靜.這里額外要說的是,該零碎特此外對(duì)用戶發(fā)來的體信息,不但能夠防止向第三方的泄露,而且即使服務(wù)器端出現(xiàn)異常,信息也不會(huì)泄露.對(duì)于私聊的方式,該零碎所采取的方法類似于QQ的通信方式,由發(fā)起方主動(dòng)連接,當(dāng)建立服務(wù)器連接請(qǐng)求接收請(qǐng)求后創(chuàng)建publicclassAppServerextendsThread{privateServerSocketserverSocket;privateServerFramesFrame;privatestaticVectoruserOnline=newVector(1,1);privatestaticVectorv=newVector(1,1);/***創(chuàng)建服務(wù)器啟動(dòng)服務(wù)監(jiān)聽1001端口**/publicAppServer(){sFrame=newServerFrame();try{serverSocket=newServerSocket(1001);//獲取服務(wù)器的主機(jī)名和IP地址InetAddressaddress=InetAddress.getLocalHost();sFrame.txtServerName.setText(address.getHostName());sFrame.txtIP.setText(address.getHostAddress());sFrame.txtPort.setText("1001");}catch(IOExceptione){fail(e,"}sFrame.txtStatus.setText("已啟動(dòng)...");this.start();//啟動(dòng)線程}/***退出服務(wù)器**異常*退出信息*/publicstaticvoidfail(Exceptione,Stringstr){System.out.println(str+"."+e);}/***監(jiān)聽客戶的請(qǐng)求,當(dāng)有效戶請(qǐng)求時(shí)創(chuàng)建Connection線程*/publicvoidrun(){try{while(true){Socketclient=serverSocket.accept();newConnection(sFrame,client,userOnline,v);//撐持多線程//System.out.println("userLength:"+userLength);}}catch(IOExceptione){System.out.println("不克不及監(jiān)聽");}}/***啟動(dòng)服務(wù)器*/publicstaticvoidmain(Stringargs[]){newAppServer();}}publicclassServerFrameextendsJFrameimplementsActionListener{publicJListlist;/****/privatestaticfinallongserialVersionUID=-8936397327038098620L;JPanelpnlServer,pnlServerInfo;JLabellblStatus,lblNumber,lblMax,lblServerName,lblProtocol,lblIP,lblPort,lblLog;publicJTextFieldtxtStatus,txtNumber,txtMax,txtServerName,txtProtocol,txtIP,txtPort;JButtonbtnStop,btnSaveLog;publicTextAreataLog;JTabbedPanetpServer;publicTextAreataMessage;JPanelpnlUser;publicJLabellblMessage,lblUser,lblNotice,lblUserCount;JListlstUser;JScrollPanespUser;JTextFieldtxtNotice;JButtonbtnSend,btnKick;publicStringti="";publicStringserverMessage="";publicServerFrame(){super("[HappyChat]聊天服務(wù)器");setSize(550,500);setDefaultClo搜索引擎優(yōu)化peration(JFrame.EXIT_ON_CLOSE);setResizable(false);Dimensionscr=Toolkit.getDefaultToolkit().getScreenSize();//在屏幕居中Dimensionfra=this.getSize();if(fra.width>scr.width){fra.width=scr.width;}if(fra.height>scr.height){fra.height=scr.height;}this.setLocation((scr.width-fra.width)/2,(scr.height-fra.height)/2);//==========服務(wù)器信息面板=========================pnlServer=newJPanel();pnlServer.setLayout(null);pnlServerInfo=newJPanel(newGridLayout(14,1));pnlServerInfo.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(""),BorderFactory.createEmptyBorder(1,1,1,1)));lblStatus=newJLabel("當(dāng)前形態(tài):");txtStatus=newJTextField(10);txtStatus.setEditable(false);lblNumber=newJLabel("當(dāng)前在耳目數(shù):");txtNumber=newJTextField("0人",10);txtNumber.setEditable(false);lblMax=newJLabel("最多在耳目數(shù):");txtMax=newJTextField("50人",10);txtMax.setEditable(false);lblServerName=newJLabel("服務(wù)器名稱:");txtServerName=newJTextField(10);txtServerName.setEditable(false);lblProtocol=newJLabel("訪問和談:");txtProtocol=newJTextField("HTTP",10);txtProtocol.setEditable(false);lblIP=newJLabel("服務(wù)器IP:");txtIP=newJTextField(10);txtIP.setEditable(false);lblPort=newJLabel("服務(wù)器端口:");txtPort=newJTextField("8000",10);txtPort.setEditable(false);btnStop=newJButton("關(guān)閉服務(wù)器(C)");btnStop.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEventarg0){closeServer();}});lblLog=newJLabel("[服務(wù)器日志]");taLog=newTextArea(20,50);btnSaveLog=newJButton("保管日志(S)");btnSaveLog.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEventarg0){saveLog();}});pnlServerInfo.add(lblStatus);pnlServerInfo.add(txtStatus);pnlServerInfo.add(lblNumber);pnlServerInfo.add(txtNumber);pnlServerInfo.add(lblMax);pnlServerInfo.add(txtMax);pnlServerInfo.add(lblServerName);pnlServerInfo.add(txtServerName);pnlServerInfo.add(lblProtocol);pnlServerInfo.add(txtProtocol);pnlServerInfo.add(lblIP);pnlServerInfo.add(txtIP);pnlServerInfo.add(lblPort);pnlServerInfo.add(txtPort);pnlServerInfo.setBounds(5,5,100,400);lblLog.setBounds(110,5,100,30);taLog.setBounds(110,35,400,370);btnStop.setBounds(200,410,120,30);btnSaveLog.setBounds(320,410,120,30);pnlServer.add(pnlServerInfo);pnlServer.add(lblLog);pnlServer.add(taLog);pnlServer.add(btnStop);pnlServer.add(btnSaveLog);//===========在線用戶面板====================pnlUser=newJPanel();pnlUser.setLayout(null);lblMessage=newJLabel("[用戶動(dòng)靜]");taMessage=newTextArea(20,20);lblNotice=newJLabel("通知:");txtNotice=newJTextField(20);btnSend=newJButton("發(fā)送(S)");btnSend.setEnabled(true);btnSend.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEventarg0){serverMessage();}});lblUserCount=newJLabel("在線總?cè)藬?shù)0人");btnKick=newJButton("踢人(K)");btnKick.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEventarg0){tiRen();}});lblUser=newJLabel("[在線用戶列表]");lstUser=newJList();lstUser.setVisibleRowCount(17);lstUser.setFixedCellWidth(180);//指定的固定單元格寬度值,而不是從列表元素計(jì)lstUser.setFixedCellHeight(18);spUser=newJScrollPane();spUser.setVerticalScrollBarPolicy(JScrollPane.spUser.getViewport().setView(lstUser);lblMessage.setBounds(5,5,100,25);taMessage.setBounds(5,35,300,360);lblUser.setBounds(310,5,100,25);spUser.setBounds(310,35,220,360);lblNotice.setBounds(5,410,40,25);txtNotice.setBounds(50,410,160,25);btnSend.setBounds(210,410,80,25);lblUserCount.setBounds(320,410,100,25);btnKick.setBounds(440,410,80,25);pnlUser.add(lblMessage);pnlUser.add(taMessage);pnlUser.add(lblUser);pnlUser.add(spUser);list=newJList();list.setListData(newString[]{""});spUser.setViewportView(list);pnlUser.add(lblNotice);pnlUser.add(txtNotice);pnlUser.add(btnSend);pnlUser.add(lblUserCount);pnlUser.add(btnKick);//============主標(biāo)簽面板========================tpServer=newJTabbedPane(JTabbedPane.TOP);tpServer.add("服務(wù)器管理",pnlServer);tpServer.add("用戶信息管理",pnlUser);this.getContentPane().add(tpServer);setVisible(true);}protectedvoidserverMessage(){this.serverMessage=txtNotice.getText();txtNotice.setText("");}protectedvoidcloseServer(){this.dispose();}protectedvoidsaveLog(){try{FileOutputStreamfileoutput=newFileOutputStream("log.txt",true);Stringtemp=taMessage.getText();fileoutput.write(temp.getBytes());fileoutput.close();JOptionPane.showMessageDialog(null,"記錄保管在log.txt");}catch(Exceptione){System.out.println(e);}}protectedvoidtiRen(){ti=list.getSelectedValue().toString();log("Ti:"+ti);}privatevoidlog(Stringstring){Stringnewta=taMessage.getText();newta+=("\n"+string);taMessage.setText(newta);}publicvoidactionPerformed(ActionEventevt){}publicstaticvoidmain(Stringargs[]){newServerFrame();}}publicclassConnectionextendsThread{/***與客戶端通訊Socket*/privateSocketnetClient;/***在線用戶列表*/privateVector<Customer>userOnline;/***聊天信息*/privateVector<Chat>userChat;/***從客戶到服務(wù)器輸入流*/privateObjectInputStreamfromClient;/***傳到客戶端打印流*/privatePrintStreamtoClient;/***注冊(cè)用戶列表*/privatestaticVectorvList=newVector();/***臨時(shí)對(duì)象*/privateObjectobj;/***服務(wù)器日志窗體*/privateServerFramesFrame;@SuppressWarnings("unchecked")/***創(chuàng)建與客戶端通訊*/publicConnection(ServerFrameframe,Socketclient,Vectoru,Vectorc){netClient=client;userOnline=u;userChat=c;sFrame=frame;try{fromClient=newObjectInputStream(netClient.getInputStream());toClient=newPrintStream(netClient.getOutputStream());}catch(IOExceptione){try{netClient.close();}catch(IOExceptione1){System.out.println("不克不及建立流"+e1);return;}}this.start();}/***處理與客戶端的通訊線程*/publicvoidrun(){try{//obj是Object類的對(duì)象obj=(Object)fromClient.readObject();if(obj.getClass().getName().equals("Customer")){//serverLogin();serverLoginDB();}if(obj.getClass().getName().equals("Register_Customer")){//serverRegiste();serverRegisteDB();}if(obj.getClass().getName().equals("Message")){serverMessage();}if(obj.getClass().getName().equals("Chat")){serverChat();}if(obj.getClass().getName().equals("Exit")){serverExit();}}catch(IOExceptione){System.out.println(e);}catch(ClassNotFoundExceptione1){System.out.println("}finally{try{netClient.close();}catch(IOExceptione){System.out.println(e);}}}/****登錄處理*/@SuppressWarnings("deprecation")publicvoidserverLogin(){try{CustomerclientMessage2=(Customer)obj;FileInputStreamfile3=newFileInputStream("user.txt");ObjectInputStreamobjInput1=newObjectInputStream(file3);vList=(Vector)objInput1.readObject();intfind=0;//查找判斷標(biāo)記//System.out.println(find);for(inti=0;i<vList.size();i++){Register_Customerreg=(Register_Customer)vList.elementAt(i);if(reg.custName.equals(clientMessage2.custName)){find=1;if(!reg.custPassword.equals(clientMessage2.custPassword)){toClient.println("密碼不準(zhǔn)確");break;}else{intlogin_flag=0;for(inta=0;a<userOnline.size();a++){String_custName=((Customer)userOnline.elementAt(a)).custName;if(clientMessage2.custName.equals(_custName)){login_flag=1;break;}}if(userOnline.size()>=50){toClient.println("登錄人數(shù)過多,請(qǐng)稍候再試");break;}if(login_flag==0){clientMessage2.custHead=reg.head;//getUserHeadByName(clientMessage2.custName);userOnline.addElement(clientMessage2);toClient.println("登錄成功");Datet=newDate();log("用戶"+clientMessage2.custNam
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 國際貿(mào)易代理基礎(chǔ)知識(shí)考核試卷
- 珠寶首飾表面處理技術(shù)考核試卷
- 玻璃制品耐候性測(cè)試與優(yōu)化考核試卷
- 稻谷種植農(nóng)業(yè)氣象服務(wù)需求與供給考核試卷
- 新材料新技術(shù)引領(lǐng)可持續(xù)發(fā)展的新方向考核試卷
- 果蔬汁飲料的企業(yè)文化與品牌建設(shè)考核試卷
- 紡織企業(yè)成本分析與控制考核試卷
- 勞務(wù)派遣企業(yè)招聘渠道分析與優(yōu)化考核試卷
- 濟(jì)南大學(xué)《模特經(jīng)紀(jì)管理》2023-2024學(xué)年第二學(xué)期期末試卷
- 江西服裝學(xué)院《嬰幼兒護(hù)理與急救》2023-2024學(xué)年第二學(xué)期期末試卷
- 2023年湖南省中學(xué)生生物學(xué)奧林匹克競(jìng)賽選拔賽試題及答案
- 升壓站建筑工程施工作業(yè)指導(dǎo)書
- GB/T 27548-2011移動(dòng)式升降工作平臺(tái)安全規(guī)則、檢查、維護(hù)和操作
- GB/T 24825-2009LED模塊用直流或交流電子控制裝置性能要求
- 2023年湖南公務(wù)員面試真題及解析匯總
- 部編人教版語文九年級(jí)下冊(cè)《18天下第一樓》課件
- 2023年東莞市網(wǎng)格員招聘筆試題庫及答案解析
- 老舊小區(qū)改造要素設(shè)計(jì)課件
- 社交網(wǎng)絡(luò)分析
- 物業(yè)綠化養(yǎng)護(hù)方案綠化管理方案
- 2022年平?jīng)鍪械诙嗣襻t(yī)院醫(yī)護(hù)人員招聘筆試試題及答案解析
評(píng)論
0/150
提交評(píng)論