Java聊天室 IO流 Socket流 GUI界面 客户端YinShenCompoent界面详解

Java聊天室 IO流 Socket流 GUI界面 客户端YinShenCompoent界面详解

效果图






  • 发送隐身/上线对象 待服务端解读 界面自身状态消失或出现
       zaixian.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                User us = new User(MainView.ss,null,null,  MsgTypeConfig.ONLINE_MSG,System.currentTimeMillis());
                try {
                    send.writeObject(us);
                } catch (IOException ioException) {
                    ioException.printStackTrace();
                }

            }
        });

代码

package SanWa.UI;

import SanWa.Net.MsgTypeConfig;
import SanWa.Net.User;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.io.ObjectOutputStream;


public class YinShenCompoent extends Box {
    public static JTextArea infortextArea1;
    public static ObjectOutputStream send= MainView.out;


    public YinShenCompoent() {

        //垂直布局
        super(BoxLayout.Y_AXIS);
        //组装视图

        Box u1Box = Box.createHorizontalBox();
        u1Box.setPreferredSize(new Dimension(850, 505));
        infortextArea1 = new JTextArea();
        infortextArea1.setEditable(false);
        infortextArea1.setBounds(0, 0, 850, 200);
        infortextArea1.setBackground(new Color(208,208,208));
        JScrollPane scrollPane21 = new JScrollPane();
        scrollPane21.setBounds(0, 0, 850, 300);
        scrollPane21.setViewportView(infortextArea1);
        u1Box.add(scrollPane21);


        JPanel btnPanel = new JPanel();
        Color color = new Color(208,208,208);
        btnPanel.setBackground(new Color(50,50,50));
        btnPanel.setMaximumSize(new Dimension(1500, 80));
        btnPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
        JLabel d11Label = new JLabel("  当前在线成员列表    ");
        d11Label.setBackground(new Color(50,50,50));
        d11Label.setForeground(Color.white);
        d11Label.setFont(new java.awt.Font("楷体", 1, 35));
        JButton getButton = new JButton("获取");
        getButton.setFont(new java.awt.Font("楷体", 1, 20));
        getButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                User us = new User(MainView.ss,null,null, MsgTypeConfig.ONLINE_LIST1,System.currentTimeMillis());
                try {
                    send.writeObject(us);
                } catch (IOException ioException) {
                    ioException.printStackTrace();
                }
                infortextArea1.setText("");

            }
        });
        JButton getButton1 = new JButton("刷新");
        getButton1.setFont(new java.awt.Font("楷体", 1, 20));
        getButton1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                User us = new User(MainView.ss,null,null, MsgTypeConfig.ONLINE_LIST1,System.currentTimeMillis());
                try {
                    send.writeObject(us);
                } catch (IOException ioException) {
                    ioException.printStackTrace();
                }
                infortextArea1.setText("");

            }
        });
        btnPanel.add(d11Label);
        btnPanel.add(getButton);
        btnPanel.add(getButton1);
        this.add(btnPanel);


        Box u5Box = Box.createHorizontalBox();
u5Box.setPreferredSize(new Dimension(650,15));
        JScrollPane scrollPane_5 = new JScrollPane();
        scrollPane_5.setPreferredSize(new Dimension(650,10));
        JPanel btn1Panel = new JPanel();
       // btn1Panel.setPreferredSize(new Dimension(650, 30));
        btn1Panel.setBackground(new Color(208,208,208));
        JLabel d1Label = new JLabel("【编号】    ");
        JLabel d2Label = new JLabel("【姓名】    ");
        JLabel d3Label = new JLabel("【IP 地 址】    ");
        JLabel d4Label = new JLabel("【端口号】   ");//组装视图
        JLabel d5Label = new JLabel("【本地端口号】   ");//组装视图
        JLabel d6Label = new JLabel("【在线状态】");//组装视图

        Color color1 = new Color(208,208,208);
        d1Label.setFont(new java.awt.Font("楷体", 1, 17));
        d2Label.setFont(new java.awt.Font("楷体", 1, 17));
        d3Label.setFont(new java.awt.Font("楷体", 1, 17));
        d4Label.setFont(new java.awt.Font("楷体", 1, 17));
        d5Label.setFont(new java.awt.Font("楷体", 1, 17));
        d6Label.setFont(new java.awt.Font("楷体", 1, 17));
        btn1Panel.setBackground(color1);
        btn1Panel.setMaximumSize(new Dimension(650, 35));
        btn1Panel.add(d1Label);
        btn1Panel.add(d2Label);
        btn1Panel.add(d3Label);
        btn1Panel.add(d4Label);
        btn1Panel.add(d5Label);
        btn1Panel.add(d6Label);

        scrollPane_5.setViewportView(btn1Panel);u5Box.add(scrollPane_5);
        this.add(u5Box);


        this.add(u1Box);

        JPanel huan = new JPanel();
        Color ys = new Color(208,208,208);
        huan.setBackground(ys);
        huan.setMaximumSize(new Dimension(1500, 80));
        huan.setLayout(new FlowLayout(FlowLayout.RIGHT));

        JButton yinshen = new JButton("隐身");
        yinshen.setFont(new java.awt.Font("楷体", 1, 20));
        yinshen.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                User us = new User(MainView.ss,null,null, MsgTypeConfig.ONLINE_MSG,System.currentTimeMillis());
                try {
                    send.writeObject(us);
                } catch (IOException ioException) {
                    ioException.printStackTrace();
                }

            }
        }); JButton zaixian = new JButton("上线");
        zaixian.setFont(new java.awt.Font("楷体", 1, 20));
        zaixian.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                User us = new User(MainView.ss,null,null,  MsgTypeConfig.ONLINE_MSG,System.currentTimeMillis());
                try {
                    send.writeObject(us);
                } catch (IOException ioException) {
                    ioException.printStackTrace();
                }

            }
        });
        huan.add(yinshen);
        huan.add(zaixian);
        this.add(huan);
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值