




版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領
文檔簡介
1、MiniQQtian_Using Java設計文檔可視化多方通信好友維護聊天記錄開發(fā)文檔、總結(jié)報告登錄窗口注冊窗口好友列表聊天窗口查找/添加好友聊天記錄對話框(登錄失敗、注冊成功、注冊失敗 確認刪除、錯誤提示等)登錄窗口注冊查找好友好友列表查找結(jié)果聊天窗口聊天記錄PackagesServer登錄驗證注冊服務好友維護聊天組維護在線用戶維護消息轉(zhuǎn)發(fā)異常處理. .Client各個窗口好友維護聊天記錄維護活動窗口維護異常處理. .Multi-ThreadSocket-ServerSocketI/O StreamJDBC (Files R/W)創(chuàng)建Thread的子類,并覆蓋run()方法實現(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)建一個數(shù)據(jù)庫MYSQLDATA mysql CREATE DATABASE MYSQLDATA; 3:選擇你所創(chuàng)建的數(shù)據(jù)庫 mysql USE MYSQLDATA; (按回車鍵出現(xiàn)Database changed 時說明操作成功!)4:查看現(xiàn)在的數(shù)據(jù)庫中存在什么表 mysql SHOW TABLES;5:創(chuàng)建一個數(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:導入.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() );/登錄驗證登錄驗證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);每一個chatWindow對應一個線程所有chatWindow按照組進行分類,并且由server負責維護討論組每個討論組里面都應該有一個數(shù)據(jù)結(jié)構(gòu)(list)維護組里的窗口服務器收發(fā)消息時向數(shù)據(jù)庫中插入聊天記錄,或者本地維護另一個數(shù)據(jù)庫,在本地插入聊天記錄采用文本文件保存聊天記錄時,可以以對方用戶名/ID為文件名分別保存不同對象的聊天記錄 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為當前用戶,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(); /獲取當前日期.格式為 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; /加入當前日期.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é)點圖片 renderer.setClosedIcon(new Ima
17、geIcon(b.jpg);/關閉樹后顯示的圖片 renderer.setOpenIcon(new ImageIcon(c.jpg);/打開樹時顯示的圖片 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等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025北京市人力資源和社會保障局勞動合同樣本
- 2025房地產(chǎn)開發(fā)合同模板
- 小區(qū)垃圾清理方案范本
- 升降道閘安裝施工方案
- 機電技術應用教授科目
- 農(nóng)場流轉(zhuǎn)合同樣本
- 2025年智能化項目委托監(jiān)理合同范本示例
- 2025年寧夏短期用工合同范本參考
- 經(jīng)營目標完成情況的檢討與調(diào)整計劃
- 班級學生個性發(fā)展的支持措施計劃
- 2025年中國工業(yè)X射線檢測設備行業(yè)市場集中度、企業(yè)競爭格局分析報告-智研咨詢發(fā)布
- 職工維權知識培訓課件
- 第15課《青春之光》課件-2024-2025學年統(tǒng)編版語文七年級下冊
- DL∕T 5161.8-2018 電氣裝置安裝工程質(zhì)量檢驗及評定規(guī)程 第8部分:盤、柜及二次回路接線施工質(zhì)量檢驗
- (正式版)HGT 22820-2024 化工安全儀表系統(tǒng)工程設計規(guī)范
- 15D501 建筑物防雷設施安裝
- 弱電安裝安全安全技術交底
- Commvault數(shù)據(jù)庫備份恢復功能介紹
- SJG 05-2020 基坑支護技術標準-高清現(xiàn)行
- 部編版語文一年級下冊第一單元教材分析及教學建議
- 洲際酒店集團--皇冠酒店設計標準手冊274P
評論
0/150
提交評論