Java+Swing+mysql仿QQ聊天工具

  • 一、系统介绍
  • 二、功能展示
    • 1.用户登陆
    • 2.好友列表
    • 3.好友聊天
    • 4.服务器日志
  • 三、系统实现
  • 四、其它
    • 1.其他系统实现
    • 2.获取源码

一、系统介绍

系统主要功能:用户登陆、好友列表、好友聊天、服务器日志

二、功能展示

1.用户登陆

2.好友列表

3.好友聊天


4.服务器日志

三、系统实现

1.Chat.java


package com.client.view;import com.client.tools.ManageChatFrame;
import com.client.tools.ManageThread;
import com.common.Message;
import com.common.MsgType;import javax.swing.*;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import java.awt.event.*;
import java.awt.*;
import java.io.IOException;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;/*** 聊天界面,点击“消息记录”按钮即可显示聊天记录,再次点击即可切换回图片*/
public class Chat extends JFrame implements ActionListener,MouseListener {private JPanel panel_north;//北部区域面板private JLabel jbl_touxiang;//头像private JLabel jbl_friendname;//好友名称private JButton btn_exit, btn_min;//最小化和关闭按钮//头像下方7个功能按钮(未实现)private JButton btn_func1_north, btn_func2_north, btn_func3_north, btn_func4_north, btn_func5_north, btn_func6_north, btn_func7_north;//聊天内容显示面板private JTextPane panel_Msg;private JPanel panel_south;//南部区域面板private JTextPane jtp_input;//消息输入区//消息输入区上方9个功能按钮(未实现)private JButton btn_func1_south, btn_func2_south, btn_func3_south,btn_func4_south, btn_func5_south, btn_func6_south, btn_func7_south, btn_func8_south, btn_func9_south;private JButton recorde_search;//查看消息记录按钮private JButton btn_send, btn_close;//消息输入区下方关闭和发送按钮private JPanel panel_east;//东部面板private CardLayout cardLayout;//卡片布局//默认东部面板显示一张图,点击查询聊天记录按钮切换到聊天记录面板private final JLabel label1 = new JLabel(new ImageIcon("image/dialogimage/hh.png"));private JTextPane panel_Record;//聊天记录显示面板private boolean isDragged = false;//鼠标拖拽窗口标志private Point frameLocation;//记录鼠标点击位置private String myId;//本人账号private String myName;private String friendId;//好友账号private DateFormat df;//日期解析public Chat(String myId, String myName, String friendId, String friendName) {this.myId = myId;this.friendId = friendId;this.myName = myName;df = new SimpleDateFormat("yyyy-MM-dd a hh:mm:ss");//获取窗口容器Container c = this.getContentPane();//设置布局c.setLayout(null);//北部面板panel_north = new JPanel();panel_north.setBounds(0, 0, 729, 92);panel_north.setLayout(null);//添加北部面板c.add(panel_north);//左上角灰色头像jbl_touxiang = new JLabel(new ImageIcon("image/dialogimage/huisetouxiang.png"));jbl_touxiang.setBounds(10, 10, 42, 42);panel_north.add(jbl_touxiang);//头像右方正在聊天的对方姓名jbl_friendname = new JLabel(friendName+"("+friendId+")");jbl_friendname.setBounds(62, 21, 105, 20);panel_north.add(jbl_friendname);//右上角最小化按钮btn_min = new JButton(new ImageIcon ("image/dialogimage/min.png"));btn_min.addActionListener(e -> setExtendedState(JFrame.ICONIFIED));btn_min.setBounds(668, 0, 30, 30);panel_north.add(btn_min);//右上角关闭按钮btn_exit = new JButton(new ImageIcon ("image/dialogimage/exit.jpg"));btn_exit.addActionListener(this);btn_exit.setBounds(698, 0, 30, 30);panel_north.add(btn_exit);//头像下方功能按钮//功能按钮1btn_func1_north = new JButton(new ImageIcon("image/dialogimage/yuyin.png"));btn_func1_north.setBounds(10, 62, 36, 30);panel_north.add(btn_func1_north);//功能按钮2btn_func2_north = new JButton(new ImageIcon("image/dialogimage/shipin.png"));btn_func2_north.setBounds(61, 62, 36, 30);panel_north.add(btn_func2_north);//功能按钮3btn_func3_north = new JButton(new ImageIcon("image/dialogimage/tranfile.jpg"));btn_func3_north.setBounds(112, 62, 36, 30);panel_north.add(btn_func3_north);//功能按钮4btn_func4_north = new JButton(new ImageIcon("image/dialogimage/createteam.jpg"));btn_func4_north.setBounds(163, 62, 36, 30);panel_north.add(btn_func4_north);//功能按钮5btn_func5_north = new JButton(new ImageIcon("image/dialogimage/yuancheng.png"));btn_func5_north.setBounds(214, 62, 36, 30);panel_north.add(btn_func5_north);//功能按钮6btn_func6_north = new JButton(new ImageIcon("image/dialogimage/sharedisplay.png"));btn_func6_north.setBounds(265, 62, 36, 30);panel_north.add(btn_func6_north);//功能按钮7btn_func7_north = new JButton(new ImageIcon("image/dialogimage/yingyong.jpg"));btn_func7_north.setBounds(318, 62, 36, 30);panel_north.add(btn_func7_north);//设置北部面板背景色//panel_north.setBackground(new Color(105, 197, 239));panel_north.setBackground(new Color(22, 154, 228));//中部聊天内容显示部分panel_Msg = new JTextPane();JScrollPane scrollPane_Msg = new JScrollPane(panel_Msg);scrollPane_Msg.setBounds(0, 92, 446, 270);c.add(scrollPane_Msg);//南部面板panel_south = new JPanel();panel_south.setBounds(0, 370, 446, 170);panel_south.setLayout(null);//添加南部面板c.add(panel_south);//内容输入区jtp_input = new JTextPane();jtp_input.setBounds(0, 34, 446, 105);//添加到南部面板panel_south.add(jtp_input);//文本输入区上方功能按钮//功能按钮1btn_func1_south = new JButton(new ImageIcon("image/dialogimage/word.png"));btn_func1_south.setBounds(10, 0, 30, 30);panel_south.add(btn_func1_south);//功能按钮2btn_func2_south = new JButton(new ImageIcon("image/dialogimage/biaoqing.png"));btn_func2_south.setBounds(47, 0, 30, 30);panel_south.add(btn_func2_south);//功能按钮3btn_func3_south = new JButton(new ImageIcon("image/dialogimage/magic.jpg"));btn_func3_south.setBounds(84, 0, 30, 30);panel_south.add(btn_func3_south);//功能按钮4btn_func4_south = new JButton(new ImageIcon("image/dialogimage/zhendong.jpg"));btn_func4_south.setBounds(121, 0, 30, 30);panel_south.add(btn_func4_south);//功能按钮5btn_func5_south = new JButton(new ImageIcon("image/dialogimage/yymessage.jpg"));btn_func5_south.setBounds(158, 0, 30, 30);panel_south.add(btn_func5_south);//功能按钮6btn_func6_south = new JButton(new ImageIcon("image/dialogimage/dgninput.jpg"));btn_func6_south.setBounds(195, 0,30, 30);panel_south.add(btn_func6_south);//功能按钮7btn_func7_south = new JButton(new ImageIcon("image/dialogimage/sendimage.jpg"));btn_func7_south.setBounds(232, 0, 30, 30);panel_south.add(btn_func7_south);//功能按钮8btn_func8_south = new JButton(new ImageIcon("image/dialogimage/diange.jpg"));btn_func8_south.setBounds(269, 0, 30, 30);panel_south.add(btn_func8_south);//功能按钮9btn_func9_south = new JButton(new ImageIcon("image/dialogimage/jietu.jpg"));btn_func9_south.setBounds(306, 0, 30, 30);panel_south.add(btn_func9_south);//查询聊天记录recorde_search = new JButton(new ImageIcon("image/dialogimage/recorde.png"));recorde_search.addActionListener(e-> {System.out.println("点击查找聊天记录");cardLayout.next(panel_east);});recorde_search.setBounds(350, 0, 96, 30);panel_south.add(recorde_search);//消息关闭按钮btn_close = new JButton(new ImageIcon("image/dialogimage/close.jpg"));btn_close.setBounds(290, 145, 64, 24);btn_close.addActionListener(this);panel_south.add(btn_close);//消息发送按钮btn_send = new JButton(new ImageIcon("image/dialogimage/send.jpg"));btn_send.addActionListener(this);btn_send.setBounds(381, 145, 64, 24);panel_south.add(btn_send);//东部面板(图片和聊天记录)panel_east = new JPanel();//卡片布局cardLayout = new CardLayout(2,2);panel_east.setLayout(cardLayout);panel_east.setBounds(444, 91, 285, 418);//添加东部面板c.add(panel_east);//显示聊天记录面板panel_Record = new JTextPane();panel_Record.setText("-----------------------------聊天记录--------------------------\n\n");JScrollPane scrollPane_Record = new JScrollPane(panel_Record);scrollPane_Record.setBounds(2, 2, 411, 410);//添加到东部面板panel_east.add(label1);panel_east.add(scrollPane_Record);//注册鼠标事件监听器this.addMouseListener(new MouseAdapter() {@Overridepublic void mouseReleased(MouseEvent e) {//鼠标释放isDragged = false;//光标恢复setCursor(new Cursor(Cursor.DEFAULT_CURSOR));}@Overridepublic void mousePressed(MouseEvent e) {//鼠标按下//获取鼠标相对窗体位置frameLocation = new Point(e.getX(),e.getY());isDragged = true;//光标改为移动形式if(e.getY() < 92)setCursor(new Cursor(Cursor.MOVE_CURSOR));}});//注册鼠标事件监听器this.addMouseMotionListener(new MouseMotionAdapter() {@Overridepublic void mouseDragged(MouseEvent e) {//指定范围内点击鼠标可拖拽if(e.getY() < 92){//如果是鼠标拖拽移动if(isDragged) {Point loc = new Point(getLocation().x+e.getX()-frameLocation.x,getLocation().y+e.getY()-frameLocation.y);//保证鼠标相对窗体位置不变,实现拖动setLocation(loc);}}}});this.setIconImage(new ImageIcon("image/login/Q.png").getImage());//修改窗体默认图标this.setSize(728, 553);//设置窗体大小this.setUndecorated(true);//去掉自带装饰框this.setVisible(true);//设置窗体可见}@Overridepublic void mouseClicked(MouseEvent e) {}@Overridepublic void mousePressed(MouseEvent e) {}@Overridepublic void mouseReleased(MouseEvent e) {}@Overridepublic void mouseEntered(MouseEvent e) {}@Overridepublic void mouseExited(MouseEvent e) {}@Overridepublic void actionPerformed(ActionEvent e) {if(e.getSource() == btn_send){System.out.println("发送");sendMsg(this, this.myName);}else if(e.getSource() == btn_close | e.getSource()  == btn_exit) {ManageChatFrame.removeChatFrame(myId + friendId);System.out.println("remove chatFrame="+myId + friendId);this.dispose();}}/*** 实现消息发送* @param f*/public void sendMsg(JFrame f, String senderName){String str = jtp_input.getText();if(!str.equals("")){Message msg = new Message();msg.setType(MsgType.COMMON_MESSAGE);msg.setSenderId(this.myId);msg.setSenderName(senderName);msg.setGetterId(this.friendId);msg.setContent(str);msg.setSendTime(df.format(new Date()));try {ObjectOutput out = new ObjectOutputStream(ManageThread.getThread(this.myId).getClient().getOutputStream());out.writeObject(msg);System.out.println("发送成功");showMessage(msg,true);jtp_input.setText("");} catch (IOException e) {e.printStackTrace();}}else{JOptionPane.showMessageDialog(f,"不能发送空内容!");}}/*** 将接收到的消息显示出来* @param msg*/public void showMessage(Message msg, boolean fromSelf) {showMessage(panel_Msg, msg, fromSelf);//先显示到聊天内容面板showMessage(panel_Record, msg, fromSelf);//再显示到聊天记录面板}/*** 将消息内容显示到指定面板* @param jtp* @param msg* @param fromSelf*/public void showMessage(JTextPane jtp, Message msg, boolean fromSelf) {//设置显示格式SimpleAttributeSet attrset = new SimpleAttributeSet();StyleConstants.setFontFamily(attrset, "仿宋");StyleConstants.setFontSize(attrset,14);Document docs = jtp.getDocument();String info = null;try {if(fromSelf){//发出去的消息内容info = "我  ";//自己账号:紫色StyleConstants.setForeground(attrset, Color.MAGENTA);docs.insertString(docs.getLength(), info, attrset); StyleConstants.setForeground(attrset, Color.red);info = msg.getSendTime()+":\n";//发送时间:绿色StyleConstants.setForeground(attrset, Color.black);docs.insertString(docs.getLength(), info, attrset);info = " "+msg.getContent()+"\n";//发送内容:黑色StyleConstants.setFontSize(attrset,16);StyleConstants.setForeground(attrset, Color.green);docs.insertString(docs.getLength(), info, attrset);}else{//接收到的消息内容info = msg.getSenderName()+"("+msg.getSenderId()+")  ";//对方账号:红色StyleConstants.setForeground(attrset, Color.red);docs.insertString(docs.getLength(), info, attrset); StyleConstants.setForeground(attrset, Color.red);info = msg.getSendTime()+":\n";//发送时间:绿色StyleConstants.setForeground(attrset, Color.black);docs.insertString(docs.getLength(), info, attrset);info = " "+msg.getContent()+"\n";//发送内容:蓝色StyleConstants.setFontSize(attrset,16);StyleConstants.setForeground(attrset, Color.blue);docs.insertString(docs.getLength(), info, attrset);}} catch (BadLocationException e) {e.printStackTrace();}}}

四、其它

1.其他系统实现

Java+Swing实现学生选课管理系统
Java+Swing实现学校教务管理系统
Java+Swing+sqlserver学生成绩管理系统
Java+Swing用户信息管理系统
Java+Swing实现的五子棋游戏
基于JavaSwing 银行管理系统
Java+Swing+mysql仿QQ聊天工具
Java+Swing 聊天室
Java+Swing+dat文件存储实现学生选课管理系统
Java+Swing可视化图像处理软件
Java+Swing学生信息管理系统
Java+Swing图书管理系统
Java+Swing图书管理系统2.0
基于java+swing+mysql图书管理系统3.0
大作业-基于java+swing+mysql北方传统民居信息管理系统

2.获取源码

点击下载
Java+Swing+mysql仿QQ聊天工具

Java+Swing+mysql仿QQ聊天工具相关推荐

  1. 【高级Java开发】类QQ聊天工具的设计与实现(代码已上传)

    1.要求 类QQ聊天工具的设计与实现,要求如下: 用户可注册并通过密码录登. 用户可通过查找添加自己的好友. 用户可通过好友列表选择好友并与之对话. 需实现聊天记录查看功能. 界面美观大方,交互设计尽 ...

  2. 仿QQ聊天工具(JAVA实现)项目总结

    闲暇之余基于Java Swing自己写了一个即时聊天软件LL,源码地址:https://github.com/nmyphp/msn532.git.欢迎大家一起改进. 一.遇到的异常及解决办法 1.   ...

  3. 基于JAVA的TCP网络QQ聊天工具系统

    目 录 1 功能设计 1 1.1功能概述 1 1.2功能模块图 1 2 逻辑设计 2 3 界面设计 4 3.1注册界面: 4 3.2登录界面 5 3.3好友列表页面 5 3.4好友聊天页面 6 3.5 ...

  4. Java实现仿QQ聊天工具的项目总结

    在写这篇文章之前,首先要感谢我的队友的辛勤付出,没有他们的付出与配合,这个项目是不能顺利完成的. 资源文件:工程文件,可运行JAR包 第一点 经验:项目开始之前应该先向老师或者学长先询问经验.或者到网 ...

  5. [源码和文档分享]基于java 的仿QQ聊天工具

    一 需求分析 本系统是基于java开发的聊天室.有用户注册.用户登陆.修改密码.忘记密码.添加好友.用户聊天.群聊功能.如果服务器还没有启动,则客户端是不可以登陆.注册.忘记密码,如果在运行过程中,服 ...

  6. java 仿qq庅_[源码和文档分享]基于java 的仿QQ聊天工具

    一 需求分析 本系统是基于java开发的聊天室.有用户注册.用户登陆.修改密码.忘记密码.添加好友.用户聊天.群聊功能.如果服务器还没有启动,则客户端是不可以登陆.注册.忘记密码,如果在运行过程中,服 ...

  7. java 仿qq 聊天工具(基于mvc三层架构,附 mvc架构模式pdf说明文档)支持开源

    用了3天多时间,因实验5要求就顺便做一下这东西吧,废话不多说,就简单说一些东西吧: 该聊天系统是基本mvc模式设计的(感觉这种模式代码比较好管理,可扩展性强),编写过程中涉及的东西比较多,包括对象实例 ...

  8. 基于java 的仿QQ聊天工具

    概要设计 在客户端:当用户登录后,生成唯一的socket, 存放在Client实体类中,在整个客户端就一个Client类和一个socket.有一个窗口控制器--ChatUIList,用来记录用户和好友 ...

  9. socket仿qq聊天工具(一)(扩展博客)

    这个项目主要是实现类似qq的一对一聊天和群聊天. 首先对于qq来说腾讯那边的服务器肯定是一直开着的,这样大家才可以登录的上去,登录上去以后会刷新你的好友列表.这样你才可以看到好友的信息,就是你拥有哪些 ...

最新文章

  1. ADO学习(十)DataGrid控件的使用
  2. Java DICOM 网络传输_DICOM医学图像处理:fo-dicom网络传输之 C-Echo and C-Store
  3. css 大于号 标签_web前端教程之怎样学好css?
  4. 解决This picacion faied to trt becuse t could, not find or load the Qt platform plugin “windows““问题
  5. 手机技巧:手机电量为啥到20%就会提醒充电,看完你就懂了!
  6. linux之history和!命令联合使用
  7. nodejs+nginx获取真实ip
  8. 数据源改变后,BarChart组件的运动效果.
  9. (转)C# Enum,Int,String的互相转换 枚举转换
  10. 一键把动态IP自动设置为静态IP
  11. 云课堂智慧职教网页版登录入口_云课堂智慧职教网页版
  12. 2020保研夏令营之路——武大网安、北理计算机、中科院信工所六室
  13. 微型计算机是以微处理器为基础,在计算机中以微处理器为核心组成的微型计算机属于第几代计算机...
  14. 与“鸡”对话的时代孤独
  15. POS收银系统报EFI Shell version 2.00错误
  16. 实验六—基本数据管理(三)
  17. 微信小程序踩坑指南--回填再造
  18. 阿里云大学安全课程-阿里云首席安全研究员吴瀚清:WannaCry事件最“细思恐极“的一个事实是?...
  19. js 校验字符串是否为数字和字母组合
  20. 域名的DA值和PA值用什么工具查询?

热门文章

  1. svmtrain的返回参数
  2. 阿里云前端开发学习路线 - CSS快速掌握 笔记
  3. Word最后一页的回车无法删除
  4. 在Scrapy中如何利用Xpath选择器从HTML中提取目标信息(两种方式)
  5. Defects4J查看错误源码
  6. Java Calendar类
  7. shell打开wifi命令_linux下使用shell命令通过wpa_cli控制wpa_supplicant连接wifi
  8. 学习笔记(05):Python数据殿堂:数据分析与数据可视化-花哨的索引,数组的排序,结构化数组...
  9. 【模拟输入模块电路分析】
  10. 大赛之Windows+iis+php+mysql搭建wordpress