![《Java程序設(shè)計》課程設(shè)計大作業(yè)-服務(wù)端聊天系統(tǒng).doc_第1頁](http://file1.renrendoc.com/fileroot_temp2/2020-2/28/b7a89b30-5c98-479d-a7e5-e43d56fbc15b/b7a89b30-5c98-479d-a7e5-e43d56fbc15b1.gif)
![《Java程序設(shè)計》課程設(shè)計大作業(yè)-服務(wù)端聊天系統(tǒng).doc_第2頁](http://file1.renrendoc.com/fileroot_temp2/2020-2/28/b7a89b30-5c98-479d-a7e5-e43d56fbc15b/b7a89b30-5c98-479d-a7e5-e43d56fbc15b2.gif)
![《Java程序設(shè)計》課程設(shè)計大作業(yè)-服務(wù)端聊天系統(tǒng).doc_第3頁](http://file1.renrendoc.com/fileroot_temp2/2020-2/28/b7a89b30-5c98-479d-a7e5-e43d56fbc15b/b7a89b30-5c98-479d-a7e5-e43d56fbc15b3.gif)
![《Java程序設(shè)計》課程設(shè)計大作業(yè)-服務(wù)端聊天系統(tǒng).doc_第4頁](http://file1.renrendoc.com/fileroot_temp2/2020-2/28/b7a89b30-5c98-479d-a7e5-e43d56fbc15b/b7a89b30-5c98-479d-a7e5-e43d56fbc15b4.gif)
![《Java程序設(shè)計》課程設(shè)計大作業(yè)-服務(wù)端聊天系統(tǒng).doc_第5頁](http://file1.renrendoc.com/fileroot_temp2/2020-2/28/b7a89b30-5c98-479d-a7e5-e43d56fbc15b/b7a89b30-5c98-479d-a7e5-e43d56fbc15b5.gif)
已閱讀5頁,還剩16頁未讀, 繼續(xù)免費閱讀
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
此文檔收集于網(wǎng)絡(luò),如有侵權(quán),請聯(lián)系網(wǎng)站刪除20112012學(xué)年第一學(xué)期Java程序設(shè)計課程大作業(yè)題目: 服務(wù)端聊天系統(tǒng) 專業(yè): 計算機 班級: 計算機1班 學(xué)號: 090400224 姓名: 馬英俊 教師: 楊樹林 日期:2011年 12月 22 日項目內(nèi)容單項分值總分選題1題目明確,系統(tǒng)功能較集中482題目難度適宜,有一定的綜合性4功能實現(xiàn)3功能完整,能夠正確運行6244模塊劃分合理,程序結(jié)構(gòu)清晰65界面設(shè)計合理、易用、協(xié)調(diào)66設(shè)計與實現(xiàn)程序6規(guī)范性及文檔7代碼規(guī)范性及注釋5108文檔內(nèi)容齊全,格式規(guī)范5總體效果9完成總體質(zhì)量61210軟件功能及技術(shù)水平6答辯11講解清楚明了,功能演示流暢66評語總分一 課程設(shè)計目的JAVA程序設(shè)計是計算機相關(guān)專業(yè)的必修專業(yè)基礎(chǔ)課程,其實踐性、應(yīng)用性很強。實踐是必不可少的一個重要環(huán)節(jié)。JAVA程序設(shè)計的設(shè)計目的是加深對理論內(nèi)容的理解和掌握,更加系統(tǒng)地掌握程序設(shè)計及其在開發(fā)中的廣泛應(yīng)用,基本方法及技巧,為綜合運用所學(xué)知識,利用軟件工程為基礎(chǔ)進行軟件開發(fā)、并在實踐應(yīng)用方面打下一定基礎(chǔ)。二 課程設(shè)計的實驗環(huán)境運行windows 2007或XP以上微機系統(tǒng),JDK,NETBEAN。三 課程設(shè)計主要內(nèi)容Java語言的學(xué)習(xí)熱潮并沒有因為時間的推移而消退,相反,由于計算機技術(shù)的發(fā)展所帶來新應(yīng)用的出現(xiàn),Java越來越流行,這種情況是以往程序設(shè)計語言在其生存周期內(nèi)所不多見的。Java語言之所以這樣長盛不衰,一是因為其眾多的技術(shù)特點與現(xiàn)今的應(yīng)用十分合拍,可以覆蓋大部分的需求;二是因為SUN公司不斷推出新的版本,完善Java自身的功能。有了這兩點,Java語言成為程序員首選的程序設(shè)計開發(fā)工具就在情理之中了。服務(wù)端聊天系統(tǒng)是一個方便于兩端用戶溝通的軟件,通過輸入偵聽方的端口號(例如:8888)來啟動服務(wù)。當服務(wù)啟動時,可進行聊天;當停止服務(wù)時,聊天信息將不再接受。四 詳細設(shè)計程序詳細設(shè)計代碼如下:package org.Adam;import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.event.*;import .*;import java.io.*;import org.Adam.PortConf;import org.Adam.ServerListen;/* * * author Administrator */public class ChatServer extends JFrame implements ActionListenerpublic static int port = 8888;/服務(wù)端的偵聽端口ServerSocket serverSocket;/服務(wù)端SocketImage icon;/程序圖標JComboBox combobox;/選擇發(fā)送消息的接受者JTextArea messageShow;/服務(wù)端的信息顯示JScrollPane messageScrollPane;/信息顯示的滾動條JTextField showStatus;/顯示用戶連接狀態(tài)JLabel sendToLabel,messageLabel;JTextField sysMessage;/服務(wù)端消息的發(fā)送JButton sysMessageButton;/服務(wù)端消息的發(fā)送按鈕UserLinkList userLinkList;/用戶鏈表/建立菜單欄JMenuBar jMenuBar = new JMenuBar(); /建立菜單組JMenu serviceMenu = new JMenu (服務(wù)(V); /建立菜單項JMenuItem portItem = new JMenuItem (端口設(shè)置(P);JMenuItem startItem = new JMenuItem (啟動服務(wù)(S);JMenuItem stopItem=new JMenuItem (停止服務(wù)(T);JMenuItem exitItem=new JMenuItem (退出(X);JMenu helpMenu=new JMenu (幫助(H);JMenuItem helpItem=new JMenuItem (幫助(H);/建立工具欄JToolBar toolBar = new JToolBar();/建立工具欄中的按鈕組件JButton portSet;/啟動服務(wù)端偵聽JButton startServer;/啟動服務(wù)端偵聽JButton stopServer;/關(guān)閉服務(wù)端偵聽JButton exitButton;/退出按鈕/框架的大小Dimension faceSize = new Dimension(400, 600);ServerListen listenThread;JPanel downPanel ;GridBagLayout girdBag;GridBagConstraints girdBagCon;/* * 服務(wù)端構(gòu)造函數(shù) */public ChatServer()init();/初始化程序/添加框架的關(guān)閉事件處理this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);this.pack();/設(shè)置框架的大小this.setSize(faceSize);/設(shè)置運行時窗口的位置Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();this.setLocation( (int) (screenSize.width - faceSize.getWidth() / 2, (int) (screenSize.height - faceSize.getHeight() / 2);this.setResizable(false);this.setTitle(聊天室服務(wù)端); /設(shè)置標題/程序圖標icon = getImage(icon.gif);this.setIconImage(icon); /設(shè)置程序圖標this.setVisible(true);/* * 程序初始化函數(shù) */public void init()Container contentPane = getContentPane();contentPane.setLayout(new BorderLayout();/添加菜單欄serviceMenu.add (portItem);serviceMenu.add (startItem);serviceMenu.add (stopItem);serviceMenu.add (exitItem);jMenuBar.add (serviceMenu); helpMenu.add (helpItem);jMenuBar.add (helpMenu); setJMenuBar (jMenuBar);/初始化按鈕portSet = new JButton(端口設(shè)置);startServer = new JButton(啟動服務(wù));stopServer = new JButton(停止服務(wù) );exitButton = new JButton(退出 );/將按鈕添加到工具欄toolBar.add(portSet);toolBar.addSeparator();/添加分隔欄toolBar.add(startServer);toolBar.add(stopServer);toolBar.addSeparator();/添加分隔欄toolBar.add(exitButton);contentPane.add(toolBar,BorderLayout.NORTH);/初始時,令停止服務(wù)按鈕不可用stopServer.setEnabled(false);stopItem .setEnabled(false);/為菜單欄添加事件監(jiān)聽portItem.addActionListener(this);startItem.addActionListener(this);stopItem.addActionListener(this);exitItem.addActionListener(this);helpItem.addActionListener(this);/添加按鈕的事件偵聽portSet.addActionListener(this);startServer.addActionListener(this);stopServer.addActionListener(this);exitButton.addActionListener(this);combobox = new JComboBox();combobox.insertItemAt(所有人,0);combobox.setSelectedIndex(0);messageShow = new JTextArea();messageShow.setEditable(false);/添加滾動條messageScrollPane = new JScrollPane(messageShow,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);messageScrollPane.setPreferredSize(new Dimension(400,400);messageScrollPane.revalidate();showStatus = new JTextField(35);showStatus.setEditable(false);sysMessage = new JTextField(24);sysMessage.setEnabled(false);sysMessageButton = new JButton();sysMessageButton.setText(發(fā)送);/添加系統(tǒng)消息的事件偵聽sysMessage.addActionListener(this);sysMessageButton.addActionListener(this);sendToLabel = new JLabel(發(fā)送至:);messageLabel = new JLabel(發(fā)送消息:);downPanel = new JPanel();girdBag = new GridBagLayout();downPanel.setLayout(girdBag);girdBagCon = new GridBagConstraints();girdBagCon.gridx = 0;girdBagCon.gridy = 0;girdBagCon.gridwidth = 3;girdBagCon.gridheight = 2;girdBagCon.ipadx = 5;girdBagCon.ipady = 5;JLabel none = new JLabel( );girdBag.setConstraints(none,girdBagCon);downPanel.add(none);girdBagCon = new GridBagConstraints();girdBagCon.gridx = 0;girdBagCon.gridy = 2;girdBagCon.insets = new Insets(1,0,0,0);girdBagCon.ipadx = 5;girdBagCon.ipady = 5;girdBag.setConstraints(sendToLabel,girdBagCon);downPanel.add(sendToLabel);girdBagCon = new GridBagConstraints();girdBagCon.gridx =1;girdBagCon.gridy = 2;girdBagCon.anchor = GridBagConstraints.LINE_START;girdBag.setConstraints(combobox,girdBagCon);downPanel.add(combobox);girdBagCon = new GridBagConstraints();girdBagCon.gridx = 0;girdBagCon.gridy = 3;girdBag.setConstraints(messageLabel,girdBagCon);downPanel.add(messageLabel);girdBagCon = new GridBagConstraints();girdBagCon.gridx = 1;girdBagCon.gridy = 3;girdBag.setConstraints(sysMessage,girdBagCon);downPanel.add(sysMessage);girdBagCon = new GridBagConstraints();girdBagCon.gridx = 2;girdBagCon.gridy = 3;girdBag.setConstraints(sysMessageButton,girdBagCon);downPanel.add(sysMessageButton);girdBagCon = new GridBagConstraints();girdBagCon.gridx = 0;girdBagCon.gridy = 4;girdBagCon.gridwidth = 3;girdBag.setConstraints(showStatus,girdBagCon);downPanel.add(showStatus);contentPane.add(messageScrollPane,BorderLayout.CENTER);contentPane.add(downPanel,BorderLayout.SOUTH);/關(guān)閉程序時的操作this.addWindowListener(new WindowAdapter()public void windowClosing(WindowEvent e)stopService();System.exit(0););/* * 事件處理 */public void actionPerformed(ActionEvent e) Object obj = e.getSource();if (obj = startServer | obj = startItem) /啟動服務(wù)端startService();else if (obj = stopServer | obj = stopItem) /停止服務(wù)端int j=JOptionPane.showConfirmDialog(this,真的停止服務(wù)嗎?,停止服務(wù),JOptionPane.YES_OPTION,JOptionPane.QUESTION_MESSAGE);if (j = JOptionPane.YES_OPTION)stopService();else if (obj = portSet | obj = portItem) /端口設(shè)置/調(diào)出端口設(shè)置的對話框PortConf portConf = new PortConf(this);portConf.setVisible(true);else if (obj = exitButton | obj = exitItem) /退出程序int j=JOptionPane.showConfirmDialog(this,真的要退出嗎?,退出,JOptionPane.YES_OPTION,JOptionPane.QUESTION_MESSAGE);if (j = JOptionPane.YES_OPTION)stopService();System.exit(0);else if (obj = helpItem) /菜單欄中的幫助/調(diào)出幫助對話框Help helpDialog = new Help(this);helpDialog.setVisible(true);else if (obj = sysMessage | obj = sysMessageButton) /發(fā)送系統(tǒng)消息sendSystemMessage();/* * 啟動服務(wù)端 */public void startService()tryserverSocket = new ServerSocket(port,10);messageShow.append(服務(wù)端已經(jīng)啟動,在+port+端口偵聽.n);startServer.setEnabled(false);startItem.setEnabled(false);portSet.setEnabled(false);portItem.setEnabled(false);stopServer .setEnabled(true);stopItem .setEnabled(true);sysMessage.setEnabled(true);catch (Exception e)/System.out.println(e);userLinkList = new UserLinkList();listenThread = new ServerListen(serverSocket,combobox,messageShow,showStatus,userLinkList);listenThread.start();/* * 關(guān)閉服務(wù)端 */public void stopService()try/向所有人發(fā)送服務(wù)器關(guān)閉的消息sendStopToAll();listenThread.isStop = true;serverSocket.close();int count = userLinkList.getCount();int i =0;while( i count)Node node = userLinkList.findUser(i);node.input .close();node.output.close();node.socket.close();i +;stopServer .setEnabled(false);stopItem .setEnabled(false);startServer.setEnabled(true);startItem.setEnabled(true);portSet.setEnabled(true);portItem.setEnabled(true);sysMessage.setEnabled(false);messageShow.append(服務(wù)端已經(jīng)關(guān)閉n);combobox.removeAllItems();combobox.addItem(所有人);catch(Exception e)/System.out.println(e);/* * 向所有人發(fā)送服務(wù)器關(guān)閉的消息 */public void sendStopToAll()int count = userLinkList.getCount();int i = 0;while(i count)Node node = userLinkList.findUser(i);if(node = null) i +;continue;trynode.output.writeObject(服務(wù)關(guān)閉);node.output.flush();catch (Exception e)/System.out.println($+e);i+;/* * 向所有人發(fā)送消息 */public void sendMsgToAll(String msg)int count = userLinkList.getCount();/用戶總數(shù)int i = 0;while(i count)Node node = userLinkList.findUser(i);if(node = null) i +;continue;trynode.output.writeObject(系統(tǒng)信息);node.output.flush();node.output.writeObject(msg);node.output.flush();catch (Exception e)/System.out.println(+e);i+;sysMessage.setText();/* * 向客戶端用戶發(fā)送消息 */public void sendSystemMessage()String toSomebody = combobox.getSelectedItem().toString();String message = sysMessage.getText() + n;messageShow.append(message);/向所有人發(fā)送消息if(toSomebody.equalsIgnoreCase(所有人)sendMsgToAll(message);else/向某個用戶發(fā)送消息Node node = userLinkList.findUser(toSomebody);trynode.output.writeObject(系統(tǒng)信息);node.output.flush();node.output.writeObject(message);node.output.flush();catch(Exception e)/System.out.println(!+e);sysMessage.setText();/將發(fā)送消息欄的消息清空/* * 通過給定的文件名獲得圖像 */Image getImage(String file
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025至2030年中國制衣型電機節(jié)電器數(shù)據(jù)監(jiān)測研究報告
- 2025至2031年中國五香鱈魚肝行業(yè)投資前景及策略咨詢研究報告
- 醫(yī)用冷療項目績效評估報告
- 2025年中國折紙盤行業(yè)市場發(fā)展前景及發(fā)展趨勢與投資戰(zhàn)略研究報告
- 2025年度建筑廢棄物再生資源利用工程承包合同
- 2025年度塔吊租賃合同(含租賃設(shè)備操作培訓(xùn)及考核)
- 2025年度商鋪租賃合同范本:商業(yè)空間租賃合同管理
- 2025年度公司法人借款資金用途監(jiān)管合同
- 2025年度住宅小區(qū)鋼筋施工勞務(wù)分包合同(含預(yù)制構(gòu)件)
- 2025年度大型設(shè)備采購及運輸項目合同范本
- 五年級上冊小數(shù)遞等式計算200道及答案
- 世界老年人跌倒的預(yù)防和管理指南解讀及跌倒應(yīng)急處理-
- GB/T 7251.2-2023低壓成套開關(guān)設(shè)備和控制設(shè)備第2部分:成套電力開關(guān)和控制設(shè)備
- 四川省地圖模板含市縣圖課件
- 帶拼音生字本模板(可A4打印)
- 小學(xué)語文必備文學(xué)常識???00題匯總(含答案)
- 英語人教版高中必修三(2019新編)第一單元教案
- 超高大截面框架柱成型質(zhì)量控制
- GB 9706.1-2020醫(yī)用電氣設(shè)備第1部分:基本安全和基本性能的通用要求
- 森林法講解課件
- 口腔頜面外科:第十六章-功能性外科與計算機輔助外科課件
評論
0/150
提交評論