#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.Mqqchat;
import qqc.mode.Mthreads;
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.File;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
public class qundeletef extends JFrame implements MouseListener {
JPanel jp;
JLabel jl1[]=new JLabel[50];
String id;
String myname;
JLabel delete;
qundeletef(String id,String myname,String qun, ArrayList<String> qunname) throws IOException {
this.id=id;
this.myname=myname;
jp=new JPanel(new GridLayout(20,1,4,4));
if(qun!=null&&!qun.equals("")) {
String[] f1 = qun.split("\\|");
for (int 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 id){
jp.remove(delete);
jp.updateUI();
}
@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("36");
m.setMyid(id);
m.setMyname(myname);
m.setOid(Mqqchat.getid(ss));
m.setOname(ss);
ObjectOutputStream oos=new ObjectOutputStream(Mthreads.getThread(id).s.getOutputStream());
oos.writeObject(m);
delete=(JLabel) e.getSource();
jp.remove(((JLabel) e.getSource()));
jp.updateUI();
} 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.群主判断
服务器判断是否为群主,发送s信息过去,做相应的判断。
}else if(m.getS().equals("36")){//删除群
Mysql my=new Mysql();
String ss=my.qun("3",m.getQun());//数据拿出群主
if(m.getMyid().equals(ss)){//判断是否为群主
oos=new ObjectOutputStream(s.getOutputStream());
oos.writeObject(m);
}else {
m.setS("37");
oos = new ObjectOutputStream(s.getOutputStream());
oos.writeObject(m);
}
}
else if(m.getS().equals("36")){//删除群
Mqqchat.getqqin(m.getMyid()).deletequn(m.getQun());
Mqqchat.getqunD(m.getMyid()).qundelete(m.getQun());
}else if(m.getS().equals("37")){//不是群主的通知
JOptionPane.showConfirmDialog(null,"抱歉你不是群主,无法删除","删除提示",JOptionPane.WARNING_MESSAGE);
}