Java課程設(shè)計ppt課件_第1頁
Java課程設(shè)計ppt課件_第2頁
Java課程設(shè)計ppt課件_第3頁
Java課程設(shè)計ppt課件_第4頁
Java課程設(shè)計ppt課件_第5頁
已閱讀5頁,還剩28頁未讀, 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

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

2、unnable接口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 /C

3、hatServer內(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() S

4、tring 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 DESC

5、RIBE 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.addAc

7、tionListener(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.createStatemen

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

10、te 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 ch

11、eckExsit(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.e

12、xists()/*檢查聊天記錄文件有無檢查聊天記錄文件有無*/ 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 (FileNotF

13、oundException e) e.printStackTrace(); catch (IOException e) e.printStackTrace(); finally if (inputStream != null) try inputStream.close(); catch (IOException e) e.printStackTrace(); /獲取當前日期.格式為 2021-02-02private static String getDate() Date date = new Date();return + s.format(date) + ; /清除記錄public v

14、oid removeMsg() line = 0; 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.sep

15、arator) + newMsg);try outputStream = 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 in

16、t getLines() return line; 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é)點圖片 rend

17、erer.setClosedIcon(new ImageIcon(b.jpg);/關(guān)閉樹后顯示的圖片 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 popMe

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

19、.addMouseListener(this);JTree右鍵菜單 tree.setCellEditor(new DefaultTreeCellEditor(tree, new DefaultTreeCellRenderer(); setSize(200, 800); popMenu = new JPopupMenu(); addItem = new JMenuItem(加入黑名單加入黑名單); addItem.addActionListener(this); delItem = new JMenuItem(刪除好友刪除好友); delItem.addActionListener(this);

20、 editItem = new JMenuItem(修改備注修改備注); editItem.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(M

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論