zoukankan      html  css  js  c++  java
  • Netty 仿QQ聊天室 (实战二)

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

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

    源码IDEA工程获取链接Java 聊天室 实战 源码

    写在前面

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

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

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

    上一篇的链接为:Java 聊天程序(百万级流量实战一):系统介绍篇

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

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

    好友列表

    消息发送UI

    群消息UI

    找人和找群

    客户端的启动代码如下:

    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) 聊天程序【 亿级流量】实战 开源项目实战


  • 相关阅读:
    C#事件(event)解析
    dll加入到GAC后,如何方便的调试
    『C程序设计』读书笔记系列文章之第四章 逻辑运算和判断选取控制
    C#委托之个人理解
    虚方法(virtual)和抽象方法(abstract)的区别
    『C程序设计』读书笔记系列文章之第二章 数据类型、运算符与表达式
    SOA概览(转)
    今天学的几个有用的句型
    【老孙随笔】PPT高手的启示
    【项目经理之修炼(11)】《初级篇》什么样的项目经理才可能成功??
  • 原文地址:https://www.cnblogs.com/crazymakercircle/p/9975448.html
Copyright © 2011-2022 走看看