完善加好友的接口
package Dao.Friends;
public interface FriendDao {
/**
* 添加好友
* 参数列表是好友类
* */
boolean add(Friend friends);
/**
* 同意添加好友之后的操作
* 将isfriend里的f1,f2,isf数据删掉
* 将f1,f2添加到friend表
* */
boolean deleteisfriend(String fid,String uid);
boolean agree(String fid,String uid);
/**
* 通过用户的账号获取他的好友信息,好友数量
* 获取到之后返回他好友的账号
* */
String[] gaininfo(String accountnum);
int gainfnum(String accountnum);
/**
* 删除好友
* 参数列表是好友类
* 将friend表中的f1,f2数据删除
* */
boolean delete(Friend friends);
/**
* 为了避免重复添加
* 查询这个用户是不是这个用户的好友
* */
boolean findf(String fid,String uid);
/**
* 查询好友申请表
* 如果user.getAccountnum=friend2就返回true
* */
boolean isadd(String accountnum);
/**
* 获取申请人信息
* */
String gaintheuser(String accountnum);
}
写加好友的控件
/**
* 获取好友申请
* */
if(fimp.isadd(user.getAcountnum())){
//获取申请人的账号
String theUsernum = fimp.gaintheuser(user.getAcountnum());
User theUser = imp.getinfo1(theUsernum);
//添加控件
AnchorPane ap1 = new AnchorPane();
ap1.setPrefHeight(60);
ImageView iv1 = new ImageView(new Image("strawberr.png"));//好友头像
iv1.setFitWidth(40);
iv1.setFitHeight(40);
Label l11 = new Label(theUser.getId()+" 请求添加你为好友");//好友名
l11.setFont(new javafx.scene.text.Font(13));
l11.setMaxWidth(300);
Button b1 = new Button("同意");
Button b2 = new Button("拒绝");
b1.setFont(new javafx.scene.text.Font(12));
b1.setMaxWidth(40);
b1.setTextFill(Paint.valueOf("#aba6a6"));
b2.setFont(new javafx.scene.text.Font(12));
b2.setMaxWidth(40);
b2.setTextFill(Paint.valueOf("#aba6a6"));
ap1.getChildren().addAll(iv1,l11,b1,b2);
AnchorPane.setLeftAnchor(iv1, 34.0);
AnchorPane.setTopAnchor(iv1, 10.0);
AnchorPane.setLeftAnchor(l11, 91.0);
AnchorPane.setTopAnchor(l11, 10.0);
AnchorPane.setLeftAnchor(b1, 91.0);
AnchorPane.setTopAnchor(b1, 36.0);
AnchorPane.setLeftAnchor(b2, 180.0);
AnchorPane.setTopAnchor(b2, 36.0);
friendVBox.getChildren().add(ap1);
//同意就添加好友
b1.setOnMouseClicked(new EventHandler<MouseEvent>() {
public void handle(MouseEvent event) {
fimp.deleteisfriend(theUsernum,user.getAcountnum());
fimp.agree(theUsernum,user.getAcountnum());
friendVBox.getChildren().remove(ap1);
}
});
//拒绝
b2.setOnMouseClicked(new EventHandler<MouseEvent>() {
public void handle(MouseEvent event) {
fimp.deleteisfriend(theUsernum,user.getAcountnum());
friendVBox.getChildren().remove(ap1);
}
});
}
结果展示
0申请添加shabi为好友
shabi点击同意之后,添加成功