#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.ActionListener;
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 qqdeletef extends JFrame implements MouseListener {
JLabel hl=new JLabel();
JPanel jp;
JLabel jl1[]=new JLabel[50];
String id;
String myname;
qqdeletef(String id,String myname,String friend, ArrayList<String> friendname) throws IOException {
this.id=id;
this.myname=myname;
jp=new JPanel(new GridLayout(50,1,4,4));
if(friend!=null&&!friend.equals("")) {//好友名单添加进列表
String[] f1 = friend.split("\\|");
for (int i = 0; i < f1.length; i++) {
String ss1=friendname.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);
}
}
@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("26");
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);
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.删除好友服务器内部
}else if(m.getS().equals("26")){//删除好友
Mysql my=new Mysql();
String ss=my.inlt("2",m.getMyid());//取出好友名单
ArrayList<String> ss1=new ArrayList<>(Arrays.asList(ss.split("\\|")));
ss1.remove(m.getOid());
ss=String.join("|",ss1);
my.update(m.getMyid(),"好友='"+ss+"'");//更新好友删除名单
ss=my.inlt("2",m.getOid());
ss1=new ArrayList<>(Arrays.asList(ss.split("\\|")));
ss1.remove(m.getMyid());
ss=String.join("|",ss1);
my.update(m.getOid(),"好友='"+ss+"'");
oos=new ObjectOutputStream(s.getOutputStream());//发送给自己
oos.writeObject(m);
if(Mythreads.getthread(m.getOid())!=null)
{
oos=new ObjectOutputStream(Mythreads.getthread(m.getOid()).s.getOutputStream());
Massage ms=new Massage();
ms.setS("26");
ms.setMyid(m.getOid());
ms.setOid(m.getMyid());
ms.setOname(m.getMyname());
ms.setMyname(m.getOname());
oos.writeObject(ms);//发送给删除的对面
}