Java課程設(shè)計(jì)(qq聊天程序)_第1頁
Java課程設(shè)計(jì)(qq聊天程序)_第2頁
Java課程設(shè)計(jì)(qq聊天程序)_第3頁
Java課程設(shè)計(jì)(qq聊天程序)_第4頁
Java課程設(shè)計(jì)(qq聊天程序)_第5頁
已閱讀5頁,還剩28頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡(jiǎn)介

1、MiniQQtian_Using Java設(shè)計(jì)文檔可視化多方通信好友維護(hù)聊天記錄開發(fā)文檔、總結(jié)報(bào)告登錄窗口注冊(cè)窗口好友列表聊天窗口查找/添加好友聊天記錄對(duì)話框(登錄失敗、注冊(cè)成功、注冊(cè)失敗 確認(rèn)刪除、錯(cuò)誤提示等)登錄窗口注冊(cè)查找好友好友列表查找結(jié)果聊天窗口聊天記錄PackagesServer登錄驗(yàn)證注冊(cè)服務(wù)好友維護(hù)聊天組維護(hù)在線用戶維護(hù)消息轉(zhuǎn)發(fā)異常處理. .Client各個(gè)窗口好友維護(hù)聊天記錄維護(hù)活動(dòng)窗口維護(hù)異常處理. .Multi-ThreadSocket-ServerSocketI/O StreamJDBC (Files R/W)創(chuàng)建Thread的子類,并覆蓋run()方法實(shí)現(xiàn)Runnab

2、le接口public class ChatServer ArrayList clients = new ArrayList();public static void main(String args) new ChatServer().begin();public void begin() ss = new ServerSocket(8888);Socket s = ss.accept();Client c = new Client(s);new Thread(c).start();clients.add(c); class Client implements Runnable /ChatSe

3、rver內(nèi)部類內(nèi)部類private Socket s;private DataInputStream dis = null;private DataOutputStream dos = null;public Client(Socket s) this.s = s; dis = new DataInputStream(s.getInputStream(); dos = new DataOutputStream(s.getOutputStream(); public void send(String str) dos.writeUTF(str); public void run() String

4、 str = dis.readUTF();for(int i=0; i SHOW DATABASES; 2:創(chuàng)建一個(gè)數(shù)據(jù)庫MYSQLDATA mysql CREATE DATABASE MYSQLDATA; 3:選擇你所創(chuàng)建的數(shù)據(jù)庫 mysql USE MYSQLDATA; (按回車鍵出現(xiàn)Database changed 時(shí)說明操作成功!)4:查看現(xiàn)在的數(shù)據(jù)庫中存在什么表 mysql SHOW TABLES;5:創(chuàng)建一個(gè)數(shù)據(jù)庫表 mysql CREATE TABLE MYTABLE (name VARCHAR(20), sex CHAR(1);6:顯示表的結(jié)構(gòu): mysql DESCRIBE

5、MYTABLE; 7:往表中加入記錄 mysql insert into MYTABLE values (hyq,M); 8:用文本方式將數(shù)據(jù)裝入數(shù)據(jù)庫表中(例如D:/mysql.txt) mysql LOAD DATA LOCAL INFILE D:/mysql.txt INTO TABLE MYTABLE;9:導(dǎo)入.sql文件命令(例如D:/mysql.sql) mysqluse database; mysqlsource d:/mysql.sql; 10:刪除表 mysqldrop TABLE MYTABLE; 11:清空表 mysqldelete from MYTABLE;12:更新表

6、中數(shù)據(jù) mysqlupdate MYTABLE set sex=f where name=hyq; MySQL-front Navicat SQLyog mysql-workbenchuserIDnamepasswordregDate. friendship ID user_ID friend_ID type frdDate . record ID user_ID friend_ID other info. .LoginfriendListfriendManagementchatWindowgroupManagementchatRecordLogin.javabtnLogin.addActio

7、nListener(new ActionListener() public void actionPerformed(ActionEvent e) boolean checked = server.verify( this.getuser() , this.password() );/登錄驗(yàn)證登錄驗(yàn)證if(checked) new friendsWindow(); loginFrame.setVisible(false);/loginFrame.dispose();else. );listFriend() /server.javaStatement s = conn.createStateme

8、nt();ResultSet rs = s.executeQuery(select , friendship.type + from user, friendship + where user.ID = friendship.friend_ID + AND friendship.user_ID = + this.getUserID()+);while(rs.next()int type = rs.getInt(type);swith (type) case 0: /friendNode.add(current);case 1: /strangeNode.add(current

9、);default: /blacklistNode.add(current);每一個(gè)chatWindow對(duì)應(yīng)一個(gè)線程所有chatWindow按照組進(jìn)行分類,并且由server負(fù)責(zé)維護(hù)討論組每個(gè)討論組里面都應(yīng)該有一個(gè)數(shù)據(jù)結(jié)構(gòu)(list)維護(hù)組里的窗口服務(wù)器收發(fā)消息時(shí)向數(shù)據(jù)庫中插入聊天記錄,或者本地維護(hù)另一個(gè)數(shù)據(jù)庫,在本地插入聊天記錄采用文本文件保存聊天記錄時(shí),可以以對(duì)方用戶名/ID為文件名分別保存不同對(duì)象的聊天記錄 private BufferedReader inputStream = null; private BufferedWriter outputStream = null; priv

10、ate StringBuilder sb = new StringBuilder(); private String file; private int line = 0; /number zero private static SimpleDateFormat s = new SimpleDateFormat(yyyy-MM-dd);/格式化日期使用public class FileManagerpublic FileManager(String userID,String friendID) checkExsit(userID,friendID); run();private void c

11、heckExsit(String userID,String friendID)/*檢查用戶聊天記錄文件夾路徑存在否,*userID為當(dāng)前用戶,friendID為好友*/ File f = new File(System.getProperties().getProperty(user.dir) + chatLog/ + userID); if(!f.exists()f.mkdirs(); file = f.getAbsolutePath() + / + friendID + .txt; f = new File(file);if (!f.exists()/*檢查聊天記錄文件有無檢查聊天記錄文

12、件有無*/ try f.createNewFile(); catch (IOException e) e.printStackTrace(); public void run() try inputStream = new BufferedReader(new FileReader(file); String l; while (l = inputStream.readLine() != null) line+; sb.append(l + System.getProperty(line.separator); catch (FileNotFoundException e) e.printSt

13、ackTrace(); catch (IOException e) e.printStackTrace(); finally if (inputStream != null) try inputStream.close(); catch (IOException e) e.printStackTrace(); /獲取當(dāng)前日期.格式為 2009-02-02private static String getDate() Date date = new Date();return + s.format(date) + ; /清除記錄public void removeMsg() line = 0;

14、sb.delete(0, getString().length(); /保存聊天記錄.public void save(String msg)String newMsg = msg; /加入當(dāng)前日期.if (msg.trim().length() != 0) newMsg = getDate() + System.getProperty(line.separator) + - + System.getProperty(line.separator) + newMsg; sb.append(System.getProperty(line.separator) + newMsg);try outp

15、utStream = new BufferedWriter(new FileWriter(file); outputStream.write(sb.toString(); catch (IOException e) e.printStackTrace();finally try outputStream.close(); catch (IOException e) e.printStackTrace(); /獲取記錄內(nèi)容public String getString() return sb.toString(); /獲取行數(shù)public int getLines() return line;

16、private JTree tree; private TreeNode node; private DefaultTreeModel model; private DefaultTreeCellRenderer renderer; model = new DefaultTreeModel(node); tree = new JTree(model); renderer = new DefaultTreeCellRenderer(); renderer.setLeafIcon(new ImageIcon(a.jpg);/葉子結(jié)點(diǎn)圖片 renderer.setClosedIcon(new Ima

17、geIcon(b.jpg);/關(guān)閉樹后顯示的圖片 renderer.setOpenIcon(new ImageIcon(c.jpg);/打開樹時(shí)顯示的圖片 tree.setCellRenderer(renderer); 頭像顯示public class TreePopupMenu extends JFrame implements MouseListener, ActionListener private static final long serialVersionUID = 1L; JTree tree; JPopupMenu popMenu; JMenuItem addItem; JMe

18、nuItem delItem; JMenuItem editItem; public TreePopupMenu() / JTree構(gòu)造 / String model = 我的好友, 陌生人, 黑名單; / tree = new JTree(model); tree = new JTree(); tree.setEditable(true); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); tree.addMouseListener(this);JTree右鍵菜單 tree

19、.setCellEditor(new DefaultTreeCellEditor(tree, new DefaultTreeCellRenderer(); setSize(200, 800); popMenu = new JPopupMenu(); addItem = new JMenuItem(加入黑名單加入黑名單); addItem.addActionListener(this); delItem = new JMenuItem(刪除好友刪除好友); delItem.addActionListener(this); editItem = new JMenuItem(修改備注修改備注); e

20、ditItem.addActionListener(this); popMenu.add(addItem); popMenu.add(delItem); popMenu.add(editItem); getContentPane().add(new JScrollPane(tree); public void mouseClicked(MouseEvent e) public void mouseEntered(MouseEvent e) public void mouseExited(MouseEvent e) public void mousePressed(MouseEvent e) TreePath path = tree.getPathForLocation(e.getX(), e.getY(); if (path = null) return; tree.setSelectionPath(path); if (e.getButton() = 3) popMenu.show(tree, e.getX(), e.getY(); public void mouseReleased(Mouse

溫馨提示

  • 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ì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論