Java聊天室系統(tǒng)方案_第1頁(yè)
Java聊天室系統(tǒng)方案_第2頁(yè)
Java聊天室系統(tǒng)方案_第3頁(yè)
Java聊天室系統(tǒng)方案_第4頁(yè)
Java聊天室系統(tǒng)方案_第5頁(yè)
已閱讀5頁(yè),還剩19頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、. . . . +學(xué) 號(hào)4武 漢 科 技 大 學(xué) 城 市 學(xué) 院課程設(shè)計(jì)報(bào) 告課程設(shè)計(jì)名稱 Java課程設(shè)計(jì) 題目 基于Java兩人聊天室系統(tǒng) 院系 信息科學(xué)與工程系 專 業(yè) 計(jì)算機(jī)科學(xué)與技術(shù) 班 級(jí) 二 班 姓 名 釗 指導(dǎo)教師 朝慶 2009年6月30日編號(hào):019題目:基于Java 網(wǎng)絡(luò)通信編程實(shí)現(xiàn)兩人聊天室系統(tǒng)1 課程設(shè)計(jì)教學(xué)條件要求 eclipse/ netbeans/ uilder 2 課程設(shè)計(jì)任務(wù)本系統(tǒng)要現(xiàn)一個(gè)兩人聊天室的Java 圖形用戶界面界面程序,主要包括如下功能:1主人可以根據(jù)輸入的IP尋找要聊天的對(duì)象。2主人和客人之間可以互相發(fā)送短消息進(jìn)行即時(shí)聊天。3 課程設(shè)計(jì)報(bào)告書主

2、要容1 需求分析2 總體設(shè)計(jì) 21 設(shè)計(jì)的總體思想與算法描述 22 模塊結(jié)構(gòu)圖 23 各功能模塊的功能與處理流程描述 24 界面設(shè)計(jì)3 各功能模塊程序設(shè)計(jì)按照功能模塊的功能與處理流程描述給出詳細(xì)的程序代碼,并給出重點(diǎn)語(yǔ)句的注釋.4 小結(jié)4 課程設(shè)計(jì)要求1 按時(shí)到機(jī)房簽到,在指定機(jī)位上機(jī)。遵守機(jī)房紀(jì)律。 2 獨(dú)立完成課程設(shè)計(jì)任務(wù)。指導(dǎo)教師到機(jī)位上指導(dǎo)學(xué)生和分時(shí)段驗(yàn)收學(xué)生完成的程序。 3 按時(shí)提交打印的課程設(shè)計(jì)報(bào)告書。5 課程設(shè)計(jì)參考書1 許文憲 懂子建. Java程序設(shè)計(jì)教程與實(shí)訓(xùn). :大學(xué),2005.2 辛運(yùn)幃 .Java程序設(shè)計(jì).:清華大學(xué), 20043 美Echel,B .Java編程思想

3、(第三版).:機(jī)械工業(yè),2005目 錄1需求分析32總體設(shè)計(jì)42.1 設(shè)計(jì)的總體思想42.2程序功能模塊設(shè)計(jì)42.2.1主窗口對(duì)象52.2.2數(shù)據(jù)庫(kù)連接對(duì)象52.2.3聊天室對(duì)象52.3界面設(shè)計(jì)62.3.1程序登錄界面設(shè)計(jì)62.3.2程序注冊(cè)界面設(shè)計(jì)62.3.3程序密碼修改界面設(shè)計(jì)72.3.4聊天室界面設(shè)計(jì)73 程序設(shè)計(jì)73.1 程序主界面設(shè)計(jì)73.2數(shù)據(jù)庫(kù)連接設(shè)計(jì)193.3聊天室設(shè)計(jì)204 小結(jié)25參考文獻(xiàn)261需求分析聊天室系統(tǒng)使用JAVA+SQL完成,ECLIPSE完成代碼編寫,JIGLOO完成界面設(shè)計(jì),SQL SERVER完成數(shù)據(jù)庫(kù)管理。聊天室通過(guò)輸入的對(duì)方IP,將JTextField

4、中的容發(fā)送到擁有此IP的主機(jī)(前提是對(duì)方也啟動(dòng)了聊天室程序)。網(wǎng)絡(luò)的通信使用UDP協(xié)議,即時(shí)搜尋網(wǎng)絡(luò)上的短消息,并可恢復(fù)對(duì)方消息。數(shù)據(jù)庫(kù)的表只有一個(gè)User_Info,用戶通過(guò)用戶管理模塊登錄,注冊(cè),修改密碼。系統(tǒng)有三個(gè)類,MainWin、ChatRoom、jdbcodbc。MainWin是程序的入口類,界面是登陸,注冊(cè),修改密碼的JFrame窗口。ChatRoom是聊天室的主窗口,負(fù)責(zé)搜發(fā)消息。jdbcodbc負(fù)責(zé)數(shù)據(jù)庫(kù)的連接,有一個(gè)構(gòu)造函數(shù),一個(gè)查詢方法,一個(gè)更新方法,三個(gè)返回方法。三個(gè)類都放在Com包里,Com包在Chat項(xiàng)目里。具體需要實(shí)現(xiàn)以下一些基本功能:l 用戶管理模塊l 數(shù)據(jù)庫(kù)連

5、接模塊l 聊天室界面2總體設(shè)計(jì)2.1 設(shè)計(jì)的總體思想程序分為三個(gè)部分:數(shù)據(jù)庫(kù)連接,聊天室管理,用戶管理。其中用戶管理有分為用戶注冊(cè),用戶登錄,用戶修改密碼。 2.2程序功能模塊設(shè)計(jì)聊天室系統(tǒng)聊天室管理模塊數(shù)據(jù)庫(kù)管理模塊用戶管理模塊用戶管理模塊用戶管理模塊用戶管理模塊圖2.1 程序功能模塊圖2.2.1主窗口對(duì)象MainWin()方法:構(gòu)造函數(shù),調(diào)用initGUI()方法以與父類JFRAME的構(gòu)造函數(shù)。main()方法:程序的入口。initGUI()方法:加載窗口的各個(gè)組件以與事件處理。2.2.2數(shù)據(jù)庫(kù)連接對(duì)象jdbcodbc():構(gòu)造函數(shù),加載數(shù)據(jù)庫(kù)驅(qū)動(dòng),建立數(shù)據(jù)庫(kù)連接。CheckInfo():

6、將查詢語(yǔ)句得到的數(shù)據(jù)庫(kù)容賦給數(shù)據(jù)集。UpdateInfo():用插入語(yǔ)句使數(shù)據(jù)庫(kù)更新。2.2.3聊天室對(duì)象ChatRoom():構(gòu)造函數(shù),調(diào)用initGUI()方法以與父類JFRAME的構(gòu)造函數(shù)。并用循環(huán)實(shí)現(xiàn)實(shí)時(shí)接受數(shù)據(jù)包里的消息。initGUI():加載窗口的各個(gè)組件以與事件處理。2.3界面設(shè)計(jì)2.3.1程序登錄界面設(shè)計(jì)圖2.2登錄界面2.3.2程序注冊(cè)界面設(shè)計(jì)圖2.3注冊(cè)界面2.3.3程序密碼修改界面設(shè)計(jì)圖2.4密碼修改界面2.3.4聊天室界面設(shè)計(jì)圖2.5聊天室界面3 程序設(shè)計(jì)3.1程序主界面設(shè)計(jì)public class MainWin extends javax.swing.JFrame

7、 public static void main(String args) MyThread th = new MyThread();th.start();public MainWin() super();initGUI();private void initGUI() try setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);this.setPreferredSize(new java.awt.Dimension(571, 395);getContentPane().setLayout(null);this.setTitle

8、("u6b22u8fceu8fdbu5165u804au5929u5ba4");getContentPane().setBackground(new java.awt.Color(236, 233, 216);this.setVisible(false);this.setResizable(false);jTabbedPane1 = new JTabbedPane();getContentPane().add(jTabbedPane1, "Center");jTabbedPane1.setBounds(0, 0, 563, 361);jTabbedPan

9、e1.setBackground(new java.awt.Color(236, 233, 216);jPanel1 = new JPanel();jTabbedPane1.addTab("登錄", null, jPanel1, null);jPanel1.setPreferredSize(new java.awt.Dimension(522, 250);jPanel1.setLayout(null);utton1 = new utton();jPanel1.add(utton1);utton1.setText("u767bu5f55");utton1.

10、setBounds(384, 176, 85, 31);utton1.setFont(new java.awt.Font("宋體", 0, 20);jTextField1 = new JTextField();jPanel1.add(jTextField1);jTextField1.setBounds(208, 80, 93, 31);jTextField1.setFont(new java.awt.Font("宋體", 0, 20);jPasswordField1 = new JPasswordField();jPanel1.add(jPassword

11、Field1);jPasswordField1.setBounds(208, 177, 93, 31);jPasswordField1.setFont(new java.awt.Font("宋體", 0, 20);jLabel1 = new JLabel();jPanel1.add(jLabel1);jLabel1.setText("u7528u6237u540duff1a");jLabel1.setBounds(52, 76, 93, 31);jLabel1.setFont(new java.awt.Font("宋體", 0, 22

12、);jLabel2 = new JLabel();jPanel1.add(jLabel2);jLabel2.setText("u5bc6 u7801uff1a");jLabel2.setBounds(52, 177, 93, 31);jLabel2.setFont(new java.awt.Font("宋體", 0, 22);jPanel2 = new JPanel();jTabbedPane1.addTab("注冊(cè)", null, jPanel2, null);jPanel2.setLayout(null);jLabel3 = ne

13、w JLabel();jPanel2.add(jLabel3);jLabel3.setText("u7528u6237u540duff1a");jLabel3.setBounds(117, 70, 65, 23);jLabel3.setFont(new java.awt.Font("宋體", 0, 22);jLabel3.setSize(93, 31);jLabel4 = new JLabel();jPanel2.add(jLabel4);jLabel4.setText("u5bc6 u7801uff1a");jLabel4.setB

14、ounds(117, 122, 93, 31);jLabel4.setFont(new java.awt.Font("宋體", 0, 22);jLabel5 = new JLabel();jPanel2.add(jLabel5);jLabel5.setText("u59d3 u540duff1a");jLabel5.setBounds(117, 180, 93, 31);jLabel5.setFont(new java.awt.Font("宋體", 0, 22);jLabel6 = new JLabel();jPanel2.add(j

15、Label6);jLabel6.setText("u6027 u522buff1a");jLabel6.setBounds(117, 237, 93, 31);jLabel6.setFont(new java.awt.Font("宋體", 0, 22);jTextField2 = new JTextField();jPanel2.add(jTextField2);jTextField2.setBounds(234, 70, 93, 31);jTextField2.setFont(new java.awt.Font("宋體", 0, 2

16、0);jPasswordField2 = new JPasswordField();jPanel2.add(jPasswordField2);jPasswordField2.setBounds(234, 122, 93, 31);jPasswordField2.setFont(new java.awt.Font("宋體", 0, 20);jTextField3 = new JTextField();jPanel2.add(jTextField3);jTextField3.setBounds(234, 180, 93, 31);jTextField3.setFont(new

17、java.awt.Font("宋體", 0, 20);jTextField4 = new JTextField();jPanel2.add(jTextField4);jTextField4.setBounds(234, 237, 93, 31);jTextField4.setFont(new java.awt.Font("宋體", 0, 20);utton2 = new utton();jPanel2.add(utton2);utton2.setText("u6ce8u518c");utton2.setBounds(373, 236,

18、 85, 31);utton2.setFont(new java.awt.Font("宋體", 0, 20);jPanel3 = new JPanel();jTabbedPane1.addTab("密碼修改", null, jPanel3, null);jPanel3.setLayout(null);jLabel7 = new JLabel();jPanel3.add(jLabel7);jLabel7.setText("u65e7u5bc6u7801uff1a");jLabel7.setBounds(98, 94, 36, 15);j

19、Label7.setFont(new java.awt.Font("宋體", 0, 22);jLabel7.setSize(93, 31);jLabel8 = new JLabel();jPanel3.add(jLabel8);jLabel8.setText("u65b0u5bc6u7801uff1a");jLabel8.setBounds(98, 148, 36, 15);jLabel8.setFont(new java.awt.Font("宋體", 0, 22);jLabel8.setSize(93, 31);jLabel9 =

20、new JLabel();jPanel3.add(jLabel9);jLabel9.setText("u786eu8ba4u5bc6u7801uff1a");jLabel9.setBounds(98, 202, 114, 31);jLabel9.setFont(new java.awt.Font("宋體", 0, 22);jPasswordField3 = new JPasswordField();jPanel3.add(jPasswordField3);jPasswordField3.setBounds(232, 94, 93, 31);jPasswo

21、rdField4 = new JPasswordField();jPanel3.add(jPasswordField4);jPasswordField4.setBounds(232, 148, 93, 31);jPasswordField5 = new JPasswordField();jPanel3.add(jPasswordField5);jPasswordField5.setBounds(232, 202, 93, 31);utton3 = new utton();jPanel3.add(utton3);utton3.setText("u786eu8ba4");utt

22、on3.setBounds(373, 203, 85, 31);utton3.setFont(new java.awt.Font("宋體", 0, 20);jTextField5 = new JTextField();jPanel3.add(jTextField5);jTextField5.setBounds(232, 42, 10, 22);jTextField5.setFont(new java.awt.Font("宋體", 0, 20);jTextField5.setSize(93, 31);jLabel10 = new JLabel();jPan

23、el3.add(jLabel10);jLabel10.setText("u7528u6237u540duff1a");jLabel10.setBounds(98, 42, 36, 15);jLabel10.setFont(new java.awt.Font("宋體", 0, 22);jLabel10.setSize(93, 31);pack();this.setSize(571, 395); catch (Exception e) e.printStackTrace();utton1.addMouseListener(new MouseAdapter()

24、 public void mouseClicked(MouseEvent e) int visible = 0;try jdbcodbc db = new jdbcodbc();db.CheckInfo("select * from User_Info");while (db.GetRS().next() if (db.GetRS().getString("ID").trim().equals(jTextField1.getText() if (db.GetRS().getString("PassWord").trim().equal

25、s(new String(jPasswordField1.getPassword() JFrame.setDefaultLookAndFeelDecorated(true);ChatRoom chatroom = new ChatRoom();chatroom.setLocationRelativeTo(null);chatroom.setVisible(true);visible = 1;/ 窗體可見,說(shuō)明用戶信息正確if (visible = 0) JOptionPane.showMessageDialog(null, "用戶信息錯(cuò)誤", "警告",

26、JOptionPane.ERROR_MESSAGE);jTextField1.setText("");jPasswordField1.setText("");jTextField1.requestFocus(); catch (SQLException sqe) );utton2.addMouseListener(new MouseAdapter() public void mouseClicked(MouseEvent e) String ID = jTextField2.getText().trim();String PassWord = new S

27、tring(jPasswordField2.getPassword();String User_Name = jTextField3.getText().trim();String User_Sex = jTextField4.getText().trim();String sql = "insert into User_Info values('" + ID + "','"+ PassWord + "','" + User_Name + "','" + Us

28、er_Sex+ "')"jdbcodbc db1 = new jdbcodbc();jdbcodbc db2 = new jdbcodbc();int visible = 0;db1.CheckInfo("select * from User_Info");try if (jTextField2.getText().length() = 0) JOptionPane.showMessageDialog(null, "請(qǐng)輸入用戶名!", "警告",JOptionPane.ERROR_MESSAGE);jTex

29、tField2.requestFocus();return;if (jTextField3.getText().length() = 0) JOptionPane.showMessageDialog(null, "請(qǐng)輸入!", "警告",JOptionPane.ERROR_MESSAGE);jTextField3.requestFocus();return;if (jTextField4.getText().length() = 0) JOptionPane.showMessageDialog(null, "請(qǐng)輸入性別!", &quo

30、t;警告",JOptionPane.ERROR_MESSAGE);jTextField4.requestFocus();return;if (jPasswordField2.getPassword().length = 0) JOptionPane.showMessageDialog(null, "請(qǐng)輸入密碼!", "警告",JOptionPane.ERROR_MESSAGE);jPasswordField2.requestFocus();return;while (db1.GetRS().next() if (db1.GetRS().getS

31、tring("ID").trim().equals(jTextField2.getText() visible = 1;if (visible = 1) JOptionPane.showMessageDialog(null, "用戶信息錯(cuò)誤", "警告",JOptionPane.ERROR_MESSAGE);jTextField2.setText("");jTextField2.requestFocus();if (visible = 0) JOptionPane.showMessageDialog(null, &

32、quot;恭喜注冊(cè)成功!", "恭喜",JOptionPane.INFORMATION_MESSAGE);db2.UpdateInfo(sql);jTextField2.setText("");jPasswordField2.setText("");jTextField3.setText("");jTextField4.setText("");jTextField2.requestFocus(); catch (SQLException sqe) );utton3.addMouseLi

33、stener(new MouseAdapter() public void mouseClicked(MouseEvent e) jdbcodbc db1 = new jdbcodbc();jdbcodbc db2 = new jdbcodbc();int visible = 0;if (jTextField5.getText().length() = 0) JOptionPane.showMessageDialog(null, "請(qǐng)輸入用戶名!", "警告",JOptionPane.ERROR_MESSAGE);jTextField5.requestF

34、ocus();return;if (jPasswordField3.getPassword().length = 0) JOptionPane.showMessageDialog(null, "請(qǐng)輸入舊密碼!", "警告",JOptionPane.ERROR_MESSAGE);jPasswordField3.requestFocus();return;if (jPasswordField4.getPassword().length = 0) JOptionPane.showMessageDialog(null, "請(qǐng)輸入新密碼!",

35、"警告",JOptionPane.ERROR_MESSAGE);jPasswordField4.requestFocus();return;if (jPasswordField5.getPassword().length = 0) JOptionPane.showMessageDialog(null, "請(qǐng)輸入密碼確認(rèn)!", "警告",JOptionPane.ERROR_MESSAGE);jPasswordField5.requestFocus();return;if (!(new String(jPasswordField5.get

36、Password().equals(new String(jPasswordField4.getPassword() JOptionPane.showMessageDialog(null, "密碼 不 一致!", "警告",JOptionPane.ERROR_MESSAGE);jPasswordField4.setText("");jPasswordField5.setText("");jPasswordField4.requestFocus();return;try db1.CheckInfo("sel

37、ect * from User_Info");while (db1.GetRS().next() if (db1.GetRS().getString("ID").trim().equals(jTextField5.getText() if (db1.GetRS().getString("PassWord").trim().equals(new String(jPasswordField3.getPassword() visible = 1;if (visible = 0) JOptionPane.showMessageDialog(null,

38、"用戶信息錯(cuò)誤", "警告",JOptionPane.ERROR_MESSAGE);jTextField5.setText("");jPasswordField3.setText("");jTextField5.requestFocus();if (visible = 1) String ID = jTextField5.getText();String PassWord = new String(jPasswordField4.getPassword();String sql = "update Use

39、r_Info set PassWord='"+ PassWord + "' where ID='" + ID + "'"db2.UpdateInfo(sql);JOptionPane.showMessageDialog(null, "修改成功", "恭喜",JOptionPane.INFORMATION_MESSAGE);jTextField5.setText("");jPasswordField3.setText("");jPass

40、wordField4.setText("");jPasswordField5.setText("");jTextField5.requestFocus(); catch (SQLException sqe) );class MyThread extends Thread public void run() JFrame.setDefaultLookAndFeelDecorated(true);MainWin inst = new MainWin();inst.setLocationRelativeTo(null);inst.setVisible(true

41、);3.2數(shù)據(jù)庫(kù)連接設(shè)計(jì)class jdbcodbc String driverClass = "sun.jdbc.odbc.JdbcOdbcDriver"String url = "jdbc:odbc:ChatDB"Statement stmt = null;ResultSet rs = null;Connection con=null;public jdbcodbc() try Class.forName(driverClass);con = DriverManager.getConnection(url); catch (ClassNotFound

42、Exception e) System.out.println("can not find driver" + driverClass);System.exit(-1); catch (SQLException e) e.printStackTrace();public void CheckInfo(String m_rs) try stmt = con.createStatement();rs = stmt.executeQuery(m_rs); catch (SQLException sqe) sqe.printStackTrace(); public void Upd

43、ateInfo(String m_rs)try stmt = con.createStatement();stmt.executeUpdate(m_rs); catch (SQLException sqe) sqe.printStackTrace();public ResultSet GetRS()return rs;public Connection GetCon()return con;public Statement GetSt()return stmt; 3.3聊天室設(shè)計(jì)public class ChatRoom extends javax.swing.JFrame DatagramS

44、ocket ds;public ChatRoom() super();try ds = new DatagramSocket(3000); catch (Exception ex) ex.printStackTrace();new Thread(new Runnable() public void run() byte buf = new byte1024;DatagramPacket dp = new DatagramPacket(buf, 1024);while (true) try ds.receive(dp);jTextArea1.append(dp.getAddress().getH

45、ostAddress()+ " : " + new String(buf, 0, dp.getLength()+ "n");jTextArea1.selectAll(); catch (Exception e) e.printStackTrace();).start();initGUI();private void initGUI() try setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);getContentPane().setLayout(null);this.setResizab

46、le(false);this.setTitle("u6b22u8fceu8fdbu5165u804au5929u5ba4");jScrollPane1 = new JScrollPane();getContentPane().add(jScrollPane1);jTextArea1 = new JTextArea();jTextArea1.setBounds(12, 12, 408, 188);jTextArea1.setBorder(BorderFactory.createMatteBorder(1, 1, 1,1, new java.awt.Color(0, 0, 0)

47、;jScrollPane1.setBounds(12, 12, 408, 188);jScrollPane1.getViewport().add(jTextArea1, null);IP = new JTextField();getContentPane().add(IP);IP.setBounds(12, 205, 97, 28);IP.setBorder(BorderFactory.createMatteBorder(1, 1, 1, 1,new java.awt.Color(0, 0, 0);Message = new JTextField();getContentPane().add(

48、Message);Message.setBounds(122, 205, 93, 28);Message.setBorder(BorderFactory.createMatteBorder(1, 1, 1, 1,new java.awt.Color(0, 0, 0);utton1 = new utton();getContentPane().add(utton1);utton1.setText("u53d1u9001");utton1.setBounds(227, 205, 87, 28);utton2 = new utton();getContentPane().add(

49、utton2);utton2.setText("u9000u51fa");utton2.setBounds(326, 205, 93, 28);pack();this.setSize(438, 273); catch (Exception e) e.printStackTrace();this.addWindowListener(new WindowAdapter() public void windowClosing(WindowEvent e) ds.close();System.exit(0););Message.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) byte buf;buf =

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(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ì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論