📄 friendsfuncpanel.java
字号:
package librarysearchingsystem;
import javax.swing.JDialog;
import javax.swing.JPanel;
import java.awt.*;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import fileUtility.StudentsManagement;
public class FriendsFuncPanel extends JPanel implements ActionListener {
// Frame f;
FriendsPanel fP;
public FriendsFuncPanel() {
try {
jbInit();
} catch (Exception ex) {
ex.printStackTrace();
}
}
private void jbInit() throws Exception {
this.setPreferredSize(new Dimension(200, 200));
this.setLayout(null);
jLabel1.setFont(new java.awt.Font("Dialog", Font.PLAIN, 14));
jLabel1.setForeground(SystemColor.windowBorder);
jLabel1.setHorizontalAlignment(SwingConstants.CENTER);
jLabel1.setText("ID:");
jLabel1.setBounds(new Rectangle(8, 15, 50, 30));
IDTextField.setText("");
IDTextField.setBounds(new Rectangle(67, 15, 117, 30));
addFriendButton.setBounds(new Rectangle(10, 58, 80, 34));
addFriendButton.setText("添加好友");
removeFiendButton.setBounds(new Rectangle(104, 58, 80, 34));
removeFiendButton.setText("删除好友");
showFriendsNotInLibButton.setBounds(new Rectangle(10, 95, 174, 28));
showFriendsNotInLibButton.setText("显示/隐藏不在图书馆的好友");
this.add(jLabel1);
this.add(IDTextField);
this.add(removeFiendButton);
this.add(addFriendButton);
this.add(showFriendsNotInLibButton);
addFriendButton.addActionListener(this);
removeFiendButton.addActionListener(this);
showFriendsNotInLibButton.addActionListener(this);
// this.setSize(200, 100);
this.setBackground(new Color(145, 111, 216));
}
JLabel jLabel1 = new JLabel();
JTextField IDTextField = new JTextField();
JButton addFriendButton = new JButton();
JButton removeFiendButton = new JButton();
JButton showFriendsNotInLibButton = new JButton();
public void actionPerformed(ActionEvent e) {
if (e.getSource() == showFriendsNotInLibButton) {
fP.isInLib = !fP.isInLib;
fP.f.refreshFriends();
return;
}
int serial = changeIDtoSerial();
if (serial < 0) {
return;
} else {
if (e.getSource() == addFriendButton) {
if (serial == fP.f.stu.serial) {
new TipsDialog("您不能添加自己为好友");
return;
}
if (fP.isFriend(serial)) {
new TipsDialog(StudentsManagement.students[serial].name +
"已经是您的好友");
return;
}
StudentsManagement.addFriend(fP.f.stu.ID, serial,
fP.friendsSerial);
fP.f.refreshFriends();
new TipsDialog("您已将" + StudentsManagement.students[serial].name +
"加为好友");
} else if (e.getSource() == removeFiendButton) {
if (!fP.isFriend(serial)) {
new TipsDialog(StudentsManagement.students[serial].name +
"不是您的好友", true);
return;
}
StudentsManagement.removeFriend(fP.f.stu.ID, serial);
fP.f.refreshFriends();
new TipsDialog("您已将" + StudentsManagement.students[serial].name +
"从好友中删除", true);
}
}
}
private int changeIDtoSerial() {
int i = 0;
int ID = 0;
try {
ID = Integer.parseInt(IDTextField.getText());
} catch (NumberFormatException ex) {
new TipsDialog("您输入的学号有误");
return -1;
}
for (; i < StudentsManagement.students.length; i++) {
if (StudentsManagement.students[i].ID == ID) {
return i;
}
}
new TipsDialog("您输入的学号有误");
return -1;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -