#8:30-9:00 签到打卡
#9:30-12:00 观看java视频
#14:00-18:00 写qq项目
1.群退出类
public class qunout extends JFrame implements MouseListener {
JPanel jp;
JLabel jl1[]=new JLabel[50];
String id;
String myname;
JLabel delete;
int i;
ArrayList<String> qunname;
qunout(String id,String myname,String qun, ArrayList<String> qunname) throws IOException {
this.id=id;
this.myname=myname;
this.qunname=qunname;
jp=new JPanel(new GridLayout(20,1,4,4));
if(qun!=null&&!qun.equals("")) {
String[] f1 = qun.split("\\|");
for ( i = 0; i < f1.length; i++) {
String ss1=qunname.get(i);
File fl=new File("src\\qqc\\massage\\"+id+"\\"+f1[i]+".jpg");
ImageIcon imge=new ImageIcon(fl.getCanonicalPath());
Image img=imge.getImage();
img=img.getScaledInstance(30,30,Image.SCALE_DEFAULT);
imge.setImage(img);
jl1[i] = new JLabel(ss1,imge,JLabel.LEFT);
jl1[i].addMouseListener(this);
jp.add(jl1[i]);
}
this.add(new JScrollPane(jp),BorderLayout.CENTER);
this.setSize(250,500);
}
}
public void qundelete(String qunname){
int i= this.qunname.indexOf(qunname);
this.qunname.remove(qunname);
jp.remove(jl1[i]);
jp.updateUI();
}
public void addqund(String qunid,String qunname) throws IOException {
this.qunname.add(qunname);
i=this.qunname.indexOf(qunname);
File fl=new File("src\\qqc\\massage\\"+id+"\\"+qunid+".jpg");
ImageIcon imge=new ImageIcon(fl.getCanonicalPath());
Image img=imge.getImage();
img=img.getScaledInstance(30,30,Image.SCALE_DEFAULT);
imge.setImage(img);
jl1[i] = new JLabel(qunname,imge,JLabel.LEFT);
jl1[i].addMouseListener(this);
jp.add(jl1[i]);
}
@Override
public void mouseClicked(MouseEvent e) {
if(e.getClickCount()==2){
int n=JOptionPane.showConfirmDialog(null,"你确定退出此群吗?","退群提示",JOptionPane.YES_NO_OPTION);
if(n==0){
String ss=((JLabel) e.getSource()).getText()+"群";
Massage m=new Massage();
try {
m.setS("39");
m.setMyid(id);
m.setMyname(myname);
m.setQun(Mqqchat.getid(ss));
m.setXiaoxi(((JLabel) e.getSource()).getText());
ObjectOutputStream oos=new ObjectOutputStream(Mthreads.getThread(id).s.getOutputStream());
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("35")){//群验证
Mysql my=new Mysql();
String ss=my.qun("3",m.getOid());
ArrayList<String> ss1=new ArrayList<String>(Arrays.asList(my.qun("1",m.getOid()).split("\\|")));
System.out.println(ss1);
System.out.println(m.getMyid());
m.setXiaoxi(ss);
if(ss1.contains(m.getMyid())){
m.setXiaoxi("你已在本群");
m.setS("40");
oos=new ObjectOutputStream(s.getOutputStream());
oos.writeObject(m);
}
else if(Mythreads.hm.containsKey(ss)){
oos=new ObjectOutputStream(Mythreads.getthread(ss).s.getOutputStream());
oos.writeObject(m);
}else{
m.setS("40");
m.setXiaoxi("群主不在线");
oos=new ObjectOutputStream(s.getOutputStream());
oos.writeObject(m);
}
}else if(m.getS().equals("38")){//群成功验证
Mysql my=new Mysql();
String ss=my.inlt("3",m.getOid());
if(ss==null||ss.equals("")){ss=m.getMyid();}
else{ ss=ss+"|"+m.getMyid();}
my.update(m.getOid(),"群='"+ss+"'");
m.setXiaoxi(ss);
ss=my.qun("1",m.getMyid());
if(ss==null||ss.equals("")){ss=m.getOid();}
else{ ss=ss+"|"+m.getOid();}
ss=my.updatequn(m.getMyid(),"群成员='"+ss+"'");
if(Mythreads.hm.containsKey(m.getOid())){
m.ss=new ArrayList<String>();
m.ss1=new ArrayList<Integer>();
m.ss2=new ArrayList<byte[]>();
File fl = new File("src\\qqserver\\view\\" + m.getMyid()+ ".jpg");
FileInputStream fis = new FileInputStream(fl.getCanonicalPath());
byte[] buf = new byte[1024];
int len;
while ((len = fis.read(buf)) != -1) {
m.ss.add(m.getOid());
m.ss1.add(len);
m.ss2.add(buf);
buf = new byte[1024];
}
oos=new ObjectOutputStream(Mythreads.getthread(m.getOid()).s.getOutputStream());
oos.writeObject(m);
}