Netty 仿QQ聊天室(实战二)

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

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


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

写在前面

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

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

​ 在上一篇中,已经完成了 整个系统的完整模块介绍。
上一篇的链接为:Java 聊天程序(百万级流量实战一):系统介绍篇

接下来,就需要一个比较高端、大气、上档次的 客户端 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) 聊天程序【 亿级流量】实战 开源项目实战

猜你喜欢

转载自blog.csdn.net/crazymakercircle/article/details/84192188