one last commit

刘星宇 5 months ago
parent 6b9d914541
commit 0e19c04bfd

@ -180,6 +180,12 @@ public class MainFrame extends JFrame {
changePasswordButton.addActionListener(e -> showPasswordChangePanel());
bottomPanel.add(changePasswordButton);
// 新增:删除账号按钮
JButton deleteAccountButton = createStyledButton("删除账号");
deleteAccountButton.setBackground(new Color(220, 20, 60)); // 红色背景提示危险操作
deleteAccountButton.addActionListener(e -> deleteAccount());
bottomPanel.add(deleteAccountButton);
JButton logoutButton = createStyledButton("退出登录");
logoutButton.addActionListener(e -> logout());
bottomPanel.add(logoutButton);
@ -188,6 +194,43 @@ public class MainFrame extends JFrame {
mainPanel.add(panel, "GradeSelection");
}
// 新增:删除当前账号功能
private void deleteAccount() {
// 简单确认对话框
int result = JOptionPane.showConfirmDialog(
this,
"确定要删除当前账号吗?\n用户名" + currentUserId + "\n此操作不可恢复",
"确认删除账号",
JOptionPane.YES_NO_OPTION,
JOptionPane.WARNING_MESSAGE
);
if (result == JOptionPane.YES_OPTION) {
// 直接使用当前用户名作为邮箱(根据您的系统设计,用户名可能就是邮箱)
// 或者让用户输入邮箱确认
String userEmail = JOptionPane.showInputDialog(
this,
"请输入您的邮箱进行确认:",
"确认删除",
JOptionPane.QUESTION_MESSAGE
);
if (userEmail != null && !userEmail.trim().isEmpty()) {
// 调用User_service的Unregister函数删除账号
String deleteResult = userService.Unregister(userEmail.trim());
if (deleteResult.equals("删除成功")) {
JOptionPane.showMessageDialog(this, "账号删除成功!");
// 清除当前用户信息并返回登录界面
currentUserId = null;
examService = null;
showLoginPanel();
} else {
JOptionPane.showMessageDialog(this, "删除失败:" + deleteResult);
}
}
}
}
private void createExamPanel() {
JPanel panel = new JPanel(new BorderLayout(10, 10));

Loading…
Cancel
Save