#8:30-9:00 签到打卡
#9:30-12:00 观看java视频
#14:00-18:00 写qq项目
1.群创建界面类
package qqc.view;
import qqc.massage.Massage;
import qqc.mode.Mthreads;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.IOException;
import java.io.ObjectOutputStream;
public class qqaddqun extends JFrame implements ActionListener, MouseListener {
public String myname;
public String id;
JTextField jt;
JButton jb,jb1[]=new JButton[2];
JPanel jp,jp1;
JTextField jl[]=new JTextField[2];
boolean flag[]=new boolean[2];
public String[] oid=new String[2];
public String[] oname=new String[2];
public String[] friendid=new String[10];
public String[] friendname=new String[10];
int i=0,j=1;
JLabel[] jll=new JLabel[10];
public qqaddqun(String id,String myname){
flag[0]=flag[1]=false;
this.myname=myname;
this.id=id;
this.setTitle(myname);
jb=new JButton("搜索");
jb.addActionListener(this);
jt=new JTextField(15);
jp=new JPanel(new GridLayout(70,1,4,4));
jp1=new JPanel();
jp1.add(jt);
jp1.add(jb);
jb1=new JButton[2];
jl[0]=new JTextField();
jl[1]=new JTextField();
jb1[0]=new JButton("添加");
jb1[0].addActionListener(this);
jb1[1]=new JButton("添加");
jb1[1].addActionListener(this);
jp.add(jl[0]);
jp.add(jb1[0]);
jp.add(jl[1]);
jp.add(jb1[1]);
this.add(jp1,BorderLayout.NORTH);
this.add(new JScrollPane(jp),BorderLayout.CENTER);
this.setSize(300,400);
}
public static void main(String[] args) {
new qqaddqun("1","流连");
}
public void shows(String id,String name){
oid[i]=id;
oname[i]=name;
jl[i].setText("群号:"+id+" 群昵称:"+name);
flag[i]=true;
i++;
}
public void shows(){
if(i==0){
jl[i].setText("很抱歉没有找到当前id的群号");
}else{
jl[i].setText("很抱歉没有找到当前名字的群号");
}
flag[i]=false;
i++;
}
public void showss(String id,String name){
jll[j]=new JLabel("群号为"+id+" 昵称为"+name+" 请求加加入此群");
jp.add(jll[j]);
friendid[j]=id;
friendname[j]=name;
jll[j].addMouseListener(this);
j++;
jp.updateUI();
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource()==jb){
try {
i=0;
ObjectOutputStream oos=new ObjectOutputStream(Mthreads.getThread(id).s.getOutputStream());
Massage m=new Massage();
m.setS("33");
m.setMyid(id);
m.setXiaoxi(jt.getText().trim());
oos.writeObject(m);
} catch (IOException ioException) {
ioException.printStackTrace();
}
}else if(e.getSource()==jb1[0]){
if(flag[0]){
int n=JOptionPane.showConfirmDialog(null,"你确定添加此群吗?","添加提示",JOptionPane.YES_NO_OPTION);
if(n==0){
try {
ObjectOutputStream oos=new ObjectOutputStream(Mthreads.getThread(id).s.getOutputStream());
Massage m=new Massage();
m.setS("34");
m.setMyid(id);
m.setMyname(myname);
m.setOid(oid[0]);
m.setOname(oname[0]);
oos.writeObject(m);
} catch (IOException ioException) {
ioException.printStackTrace();
}
}
}
}else if(e.getSource()==jb1[1]){
if(flag[1]){
int n=JOptionPane.showConfirmDialog(null,"你确定添加此群吗?","添加提示",JOptionPane.YES_NO_OPTION);
if(n==0){
try {
ObjectOutputStream oos=new ObjectOutputStream(Mthreads.getThread(id).s.getOutputStream());
Massage m=new Massage();
m.setS("22");
m.setMyid(id);
m.setMyname(myname);
m.setOid(oid[1]);
m.setOname(oname[1]);
oos.writeObject(m);
} catch (IOException ioException) {
ioException.printStackTrace();
}
}
}
}
}
@Override
public void mouseClicked(MouseEvent e) {
if(e.getClickCount()==2){
int n=JOptionPane.showConfirmDialog(null,"你同意添加他群友吗?","添加提示",JOptionPane.YES_NO_OPTION);
if(n==0){
for(int i=0;i<10;i++){
if (jll[i]==e.getSource()) {
try {
ObjectOutputStream oos=new ObjectOutputStream(Mthreads.getThread(id).s.getOutputStream());
Massage m=new Massage();
m.setS("23");
m.setMyid(id);
m.setMyname(myname);
m.setOid(friendid[i]);
m.setOname(friendname[i]);
oos.writeObject(m);
} catch (IOException ioException) {
ioException.printStackTrace();
}
}
}
}
}
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
}
2.服务器添加群方法
}else if(m.getS().equals("33")){
oos=new ObjectOutputStream(s.getOutputStream());
Mysql my=new Mysql();
String ss=my.qun("2",m.getXiaoxi());
if(ss!=null){
m.setS("33");
m.setOname(ss);
m.setOid(m.getXiaoxi());
oos.writeObject(m);}
else{
m.setS("34");
oos.writeObject(m);
}
oos=new ObjectOutputStream(s.getOutputStream());
ss=my.seclectall("4","name = '"+m.getXiaoxi()+"'");
if(ss!=null){
m.setS("33");
m.setOname(m.getXiaoxi());
m.setOid(ss);
oos.writeObject(m);}
else {
m.setS("34");
oos.writeObject(m);
}