Netty 仿QQ聊天室(实战二)
发布日期:2021-05-06 17:50:21 浏览次数:18 分类:精选文章

本文共 3603 字,大约阅读时间需要 12 分钟。

Netty 聊天器(百万级流量实战二):仿QQ客户端

疯狂创客圈 Java 分布式聊天室【 亿级流量】实战系列之15 【 】


源码IDEA工程获取链接

写在前面

​ 大家好,我是作者尼恩。

​ 今天是百万级流量 Netty 聊天器 打造的系列文章的第二篇, 设计一个 仿QQ客户端。

​ 在上一篇中,已经完成了 整个系统的完整模块介绍。

上一篇的链接为:

接下来,就需要一个比较高端、大气、上档次的 客户端 UI界面了

​ 对于主要的UI界面实现,列表如下:

好友列表

img

消息发送UI

img

群消息UI

img

找人和找群

img

客户端的启动代码如下:

public class MainDialog extends BaseDialog{    private static final long serialVersionUID = 1L;    private OnlyPanel topPanel = new OnlyPanel();    private OnlyPanel titlePanel = new OnlyPanel();    private OnlyPanel mainPanel = new OnlyPanel();    private OnlyPanel bottomPanel = new OnlyPanel();    private UserDataPanel userDataPanel = new UserDataPanel();    private TabPanel tabPanel = new TabPanel();    private Root userRoot = new Root();    private Root groupRoot = new Root();    private Root lastRoot = new Root();    public MainDialog()    {        super(new javax.swing.JFrame(), false);        initComponents();    }    /**     * Creates new form MainDialog     */    public MainDialog(java.awt.Frame parent, boolean modal)    {        super(parent, modal);        initComponents();        initUserList();    }    private void initComponents()    {        this.setSize(280, 630);        this.setMinimumSize(new java.awt.Dimension(280, 530));  // ...    }    public static void main(String args[])    {        try        {            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels())            {                if ("Nimbus".equals(info.getName()))                {                    javax.swing.UIManager.setLookAndFeel(info.getClassName());                    break;                }            }        } catch (ClassNotFoundException ex)        {            java.util.logging.Logger.getLogger(MainDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);        } catch (InstantiationException ex)        {            java.util.logging.Logger.getLogger(MainDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);        } catch (IllegalAccessException ex)        {            java.util.logging.Logger.getLogger(MainDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);        } catch (javax.swing.UnsupportedLookAndFeelException ex)        {            java.util.logging.Logger.getLogger(MainDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);        }        java.awt.EventQueue.invokeLater(new Runnable()        {            public void run()            {                MainDialog dialog = new MainDialog(new javax.swing.JFrame(), true);                dialog.addWindowListener(new java.awt.event.WindowAdapter()                {                    @Override                    public void windowClosing(java.awt.event.WindowEvent e)                    {                        System.exit(0);                    }                });                Image imaeg = new ImageIcon("Resources/Images/Login/002.jpg").getImage();                BufferedImage bi = new BufferedImage(imaeg.getWidth(null), imaeg.getHeight(null), BufferedImage.TYPE_INT_RGB);                Graphics2D biContext = bi.createGraphics();                biContext.drawImage(imaeg, 0, 0, null);                bi = OnlyImageUtil.applyGaussianFilter(bi, null, 50);                dialog.setBackgroundImage(bi);                dialog.setVisible(true);            }        });    }}

写在最后

​ 至此为止,终于仿QQ的高大上 UI 客户端介绍。

​ 在这里,致敬和感恩网友夏辉,本实例的UI代码,整合自他的mina 聊天器客户端。他的项目也是开放的和学习型的,由于重写一个客户端,需要挺长时间的,这里先借鉴一下,后续有时间,再重新实现。

​ 为了完成百万级的聊天,代码中,还是有很多需要优化的、升级的地方。

​ 后续的文章,专门介绍如何优化。


疯狂创客圈 实战计划
  • Java (Netty) 聊天程序【 亿级流量】实战 开源项目实战
  • Netty 源码、原理、JAVA NIO 原理
  • Java 面试题 一网打尽
  • 疯狂创客圈

上一篇:ByteBuf(秒懂)- 图解Netty系列
下一篇:Netty聊天程序(实战一):从0开始实战100w级流量应用

发表评论

最新留言

路过按个爪印,很不错,赞一个!
[***.219.124.196]2025年03月21日 18时18分53秒