2021/8/30

#8:30-9:00 签到打卡

#9:30-12:00 观看java视频

#14:00-18:00 写qq项目

1.qq群创建

package qqc.view;

import qqc.massage.Massage;
import qqc.mode.Mthreads;
import qqc.mode.qqlogin;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;
import java.util.ArrayList;

public class qunzhu extends JFrame implements ActionListener {//qq群界面
    JPanel jp;
    JPanel jp1, jp2, jp3;
    JLabel jl1, jl3, jp4, jp6, JL, jl7;
    JTextField jt1, jt3;
    JButton jb1, jb2;
    JFileChooser jfc;
    String ss;
    File tupian;
    public String id;
    qunzhu(String id) throws IOException {
        this.id=id;

        jp4 = new JLabel("请输入1-10数字", SwingConstants.CENTER);
        jp6 = new JLabel("任意输入20以内", SwingConstants.CENTER);
        jp2 = new JPanel();
        jb1 = new JButton("提交");
        jp1 = new JPanel(new GridLayout(2, 3, 0, 0));
        jl1 = new JLabel("群账号", SwingConstants.CENTER);
        jl3 = new JLabel("群昵称", SwingConstants.CENTER);
        jt1 = new JTextField();
        jt3 = new JTextField();
        jp1.add(jl1);
        jp1.add(jt1);
        jp1.add(jp4);
        jp1.add(jl3);
        jp1.add(jt3);
        jp1.add(jp6);
        jp2.add(jb1);
        jp3 = new JPanel();
        jb2 = new JButton("浏览");
        jb1.addActionListener(this);
        jb2.addActionListener(this);
        File fl = new File("src\\qqc\\view\\空白.jpg");
        tupian = new File(fl.getCanonicalPath());
        ImageIcon imge = new ImageIcon(fl.getCanonicalPath());
        Image img = imge.getImage();
        img = img.getScaledInstance(100, 100, Image.SCALE_DEFAULT);
        imge.setImage(img);
        JL = new JLabel(imge);
        jl7 = new JLabel("背景图片");
        jp3.add(jl7, SwingConstants.CENTER);
        jp3.add(JL);
        jp3.add(jb2);
        jp = new JPanel();
        this.setSize(350, 260);
        jp.add(jp3, BorderLayout.NORTH);
        jp.add(jp1, BorderLayout.CENTER);
        jp.add(jp2, BorderLayout.SOUTH);
        jp.setBorder(BorderFactory.createLineBorder(Color.BLUE));

        this.add(jp, BorderLayout.CENTER);
        this.setVisible(true);
    }

    public static void main(String[] args) throws IOException {
        new qunzhu("1");
    }

    @Override
    public void actionPerformed(ActionEvent e) {//提交按钮
        if (e.getSource() == jb1) {
            String s = jt1.getText().trim();
            if (s.length() > 10 || s.equals("")) {
                JOptionPane.showConfirmDialog(null, "账号输入不正确", "提示", JOptionPane.WARNING_MESSAGE);
                return;
            } else {
                boolean flag = true;
                for (int i = 0; i < s.length(); i++) {
                    if (!Character.isDigit(s.charAt(i))) {
                        flag = false;
                        break;
                    }
                }
                if (!flag) {
                    JOptionPane.showConfirmDialog(null, "账号输入不正确", "提示", JOptionPane.WARNING_MESSAGE);
                    return;
                }
            }

            s = jt3.getText().trim();
            if (s.length() > 20 || s.equals("")) {
                JOptionPane.showConfirmDialog(null, "昵称不正确", "提示", JOptionPane.WARNING_MESSAGE);
                return;
            }
            Massage m=new Massage();
            m.setS("30");
            m.setMyname(jt3.getText().trim());
            m.setMyid(jt1.getText().trim());
            m.ss=new ArrayList<String>();
            m.ss1=new ArrayList<Integer>();
            m.ss2=new ArrayList<byte[]>();
            File fl=new File(tupian.getPath());
            FileInputStream fis= null;
            int len;
            byte[] buf=new byte[1024];
            try {
                fis = new FileInputStream(fl.getPath());
                while((len=fis.read(buf))!=-1){
                    m.ss.add(m.getMyid());
                    m.ss1.add(len);
                    m.ss2.add(buf);
                    buf=new byte[1024];
                }
            } catch (FileNotFoundException fileNotFoundException) {
                fileNotFoundException.printStackTrace();
            } catch (IOException ioException) {
                ioException.printStackTrace();
            }
            try {
                ObjectOutputStream oos=new ObjectOutputStream(Mthreads.getThread(id).s.getOutputStream());
                oos.writeObject(m);
            } catch (IOException ioException) {
                ioException.printStackTrace();
            }
        }else if(e.getSource()==jb2){//选择图片
            jfc=new JFileChooser();
            int i=jfc.showOpenDialog(this);
            if(i==jfc.APPROVE_OPTION){
                tupian=jfc.getSelectedFile();
                Image image=new ImageIcon(tupian.getPath()).getImage();
                image=image.getScaledInstance(100,100,Image.SCALE_DEFAULT);
                JL.setIcon(new ImageIcon(image));
            }
        }
    }
}

2.服务器客服端处理数据

  }else if(m.getS().equals("30")){//服务器创建群

                }else if(m.getS().equals("36")){//删除群
                    Mysql my=new Mysql();
                    String ss=my.qun("3",m.getQun());
                    if(m.getMyid().equals(ss)){
                        ArrayList<String> ss1=new ArrayList<>(Arrays.asList(my.qun("1",m.getQun()).split("\\|")));
                        for(String id:ss1){
                            ArrayList<String> ss2=new ArrayList<String>(Arrays.asList(my.inlt("3",id).split("\\|")));
                            ss2.remove(m.getQun());
                            String ss3=String.join("|",ss2);
                            my.update(id,"群='"+ss3+"'");
                        }
                        my.deletequn(m.getQun());
                        oos=new ObjectOutputStream(s.getOutputStream());
                        oos.writeObject(m);                



}else if(m.getS().equals("30")){//群创建成功
                    Mqqchat.getqqin(m.getMyid());
                    Mqqchat.getqunD(m.getMyid());
                }else if(m.getS().equals("31")){//群创建失败
                    JOptionPane.showConfirmDialog(null,"抱歉此群号已创建","群创建提示",JOptionPane.WARNING_MESSAGE);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值