|
|
|
|
@ -20,6 +20,10 @@ import javafx.scene.text.Font;
|
|
|
|
|
import javafx.scene.text.FontWeight;
|
|
|
|
|
import javafx.scene.text.Text;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 主菜单视图类,提供应用程序的主导航界面.
|
|
|
|
|
* 包含用户信息显示、开始练习、修改密码和退出登录等功能.
|
|
|
|
|
*/
|
|
|
|
|
public class MainMenuView {
|
|
|
|
|
private Scene scene;
|
|
|
|
|
private final SceneManager sceneManager;
|
|
|
|
|
@ -30,12 +34,20 @@ public class MainMenuView {
|
|
|
|
|
private Text avatarText;
|
|
|
|
|
private Label welcomeLabel;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 构造函数,初始化主菜单视图.
|
|
|
|
|
*
|
|
|
|
|
* @param sceneManager 场景管理器,用于界面导航.
|
|
|
|
|
*/
|
|
|
|
|
public MainMenuView(SceneManager sceneManager) {
|
|
|
|
|
this.sceneManager = sceneManager;
|
|
|
|
|
this.currentUsername = sceneManager.getCurrentUserName();
|
|
|
|
|
createScene();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 创建主场景,包含用户信息栏和菜单内容区域.
|
|
|
|
|
*/
|
|
|
|
|
private void createScene() {
|
|
|
|
|
// 创建主容器
|
|
|
|
|
VBox mainContainer = new VBox();
|
|
|
|
|
@ -52,111 +64,237 @@ public class MainMenuView {
|
|
|
|
|
scene = new Scene(mainContainer, 450, 550);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 创建用户信息栏,包含用户头像和用户名显示.
|
|
|
|
|
*
|
|
|
|
|
* @return HBox 用户信息栏布局容器.
|
|
|
|
|
*/
|
|
|
|
|
private HBox createUserInfoBar() {
|
|
|
|
|
HBox userInfoBar = new HBox(15);
|
|
|
|
|
userInfoBar.setAlignment(Pos.CENTER_LEFT);
|
|
|
|
|
userInfoBar.setPadding(new Insets(0, 0, 30, 0));
|
|
|
|
|
userInfoBar.setStyle("-fx-border-color: #e0e0e0; -fx-border-width: 0 0 1 0; -fx-padding: 0 0 15 0;");
|
|
|
|
|
userInfoBar.setStyle("-fx-border-color: #e0e0e0; -fx-border-width: 0 0 1 0; "
|
|
|
|
|
+ "-fx-padding: 0 0 15 0;");
|
|
|
|
|
|
|
|
|
|
// 创建圆形头像容器
|
|
|
|
|
// 用户名标签
|
|
|
|
|
usernameLabel = new Label(currentUsername != null ? currentUsername : "用户");
|
|
|
|
|
usernameLabel.setFont(Font.font("Arial", FontWeight.BOLD, 16));
|
|
|
|
|
usernameLabel.setStyle("-fx-text-fill: #2c3e50;");
|
|
|
|
|
|
|
|
|
|
// 间隔
|
|
|
|
|
Region spacer = new Region();
|
|
|
|
|
HBox.setHgrow(spacer, Priority.ALWAYS);
|
|
|
|
|
// 创建头像容器
|
|
|
|
|
VBox avatarContainer = createAvatarContainer();
|
|
|
|
|
|
|
|
|
|
userInfoBar.getChildren().addAll(avatarContainer, usernameLabel, spacer);
|
|
|
|
|
|
|
|
|
|
return userInfoBar;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 创建头像容器,包含圆形头像背景和用户首字母.
|
|
|
|
|
*
|
|
|
|
|
* @return VBox 头像容器布局.
|
|
|
|
|
*/
|
|
|
|
|
private VBox createAvatarContainer() {
|
|
|
|
|
VBox avatarContainer = new VBox();
|
|
|
|
|
avatarContainer.setAlignment(Pos.CENTER);
|
|
|
|
|
avatarContainer.setPrefSize(50, 50);
|
|
|
|
|
|
|
|
|
|
// 创建圆形头像背景
|
|
|
|
|
Circle avatarCircle = new Circle(22);
|
|
|
|
|
avatarCircle.setFill(Color.web("#4CAF50"));
|
|
|
|
|
avatarCircle.setStroke(Color.WHITE);
|
|
|
|
|
avatarCircle.setStrokeWidth(2);
|
|
|
|
|
|
|
|
|
|
// 添加阴影效果
|
|
|
|
|
avatarCircle.setStyle("-fx-effect: dropshadow(gaussian, rgba(0,0,0,0.2), 5, 0.3, 2, 2);");
|
|
|
|
|
|
|
|
|
|
// 添加首字母文本
|
|
|
|
|
avatarText = new Text(getFirstLetter());
|
|
|
|
|
avatarText.setFill(Color.WHITE);
|
|
|
|
|
avatarText.setFont(Font.font("Arial", FontWeight.BOLD, 16));
|
|
|
|
|
|
|
|
|
|
// 创建圆形头像背景
|
|
|
|
|
Circle avatarCircle = createAvatarCircle();
|
|
|
|
|
|
|
|
|
|
// 使用StackPane将文本放在圆形中心
|
|
|
|
|
javafx.scene.layout.StackPane avatarStack = new javafx.scene.layout.StackPane();
|
|
|
|
|
javafx.scene.layout.StackPane avatarStack =
|
|
|
|
|
new javafx.scene.layout.StackPane();
|
|
|
|
|
avatarStack.getChildren().addAll(avatarCircle, avatarText);
|
|
|
|
|
avatarStack.setPrefSize(44, 44);
|
|
|
|
|
avatarStack.setAlignment(Pos.CENTER);
|
|
|
|
|
|
|
|
|
|
avatarContainer.getChildren().add(avatarStack);
|
|
|
|
|
return avatarContainer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 用户名标签
|
|
|
|
|
usernameLabel = new Label(currentUsername != null ? currentUsername : "用户");
|
|
|
|
|
usernameLabel.setFont(Font.font("Arial", FontWeight.BOLD, 16));
|
|
|
|
|
usernameLabel.setStyle("-fx-text-fill: #2c3e50;");
|
|
|
|
|
|
|
|
|
|
// 间隔
|
|
|
|
|
Region spacer = new Region();
|
|
|
|
|
HBox.setHgrow(spacer, Priority.ALWAYS);
|
|
|
|
|
|
|
|
|
|
userInfoBar.getChildren().addAll(avatarContainer, usernameLabel, spacer);
|
|
|
|
|
/**
|
|
|
|
|
* 创建圆形头像背景.
|
|
|
|
|
*
|
|
|
|
|
* @return Circle 圆形头像背景对象.
|
|
|
|
|
*/
|
|
|
|
|
private Circle createAvatarCircle() {
|
|
|
|
|
Circle avatarCircle = new Circle(22);
|
|
|
|
|
avatarCircle.setFill(Color.web("#4CAF50"));
|
|
|
|
|
avatarCircle.setStroke(Color.WHITE);
|
|
|
|
|
avatarCircle.setStrokeWidth(2);
|
|
|
|
|
|
|
|
|
|
return userInfoBar;
|
|
|
|
|
// 添加阴影效果
|
|
|
|
|
avatarCircle.setStyle("-fx-effect: dropshadow(gaussian, rgba(0,0,0,0.2), "
|
|
|
|
|
+ "5, 0.3, 2, 2);");
|
|
|
|
|
return avatarCircle;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 创建主菜单内容区域.
|
|
|
|
|
*
|
|
|
|
|
* @return VBox 菜单内容区域布局容器.
|
|
|
|
|
*/
|
|
|
|
|
private VBox createMenuContent() {
|
|
|
|
|
VBox menuContent = new VBox(25);
|
|
|
|
|
menuContent.setPadding(new Insets(20));
|
|
|
|
|
menuContent.setAlignment(Pos.CENTER);
|
|
|
|
|
|
|
|
|
|
// 创建标题区域
|
|
|
|
|
VBox titleSection = createTitleSection();
|
|
|
|
|
|
|
|
|
|
// 创建功能按钮区域
|
|
|
|
|
VBox buttonSection = createButtonSection();
|
|
|
|
|
|
|
|
|
|
menuContent.getChildren().addAll(titleSection, buttonSection);
|
|
|
|
|
|
|
|
|
|
return menuContent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 创建标题区域,包含主标题和欢迎信息.
|
|
|
|
|
*
|
|
|
|
|
* @return VBox 标题区域布局容器.
|
|
|
|
|
*/
|
|
|
|
|
private VBox createTitleSection() {
|
|
|
|
|
VBox titleSection = new VBox(10);
|
|
|
|
|
titleSection.setAlignment(Pos.CENTER);
|
|
|
|
|
|
|
|
|
|
Label titleLabel = new Label("数学学习软件");
|
|
|
|
|
titleLabel.setFont(Font.font(28));
|
|
|
|
|
titleLabel.setStyle("-fx-text-fill: #2c3e50;");
|
|
|
|
|
|
|
|
|
|
// 修改欢迎标签,显示用户名
|
|
|
|
|
welcomeLabel = new Label("欢迎," + (currentUsername != null ? currentUsername : "用户") + "!");
|
|
|
|
|
welcomeLabel = new Label("欢迎,"
|
|
|
|
|
+ (currentUsername != null ? currentUsername : "用户") + "!");
|
|
|
|
|
welcomeLabel.setFont(Font.font(18));
|
|
|
|
|
welcomeLabel.setStyle("-fx-text-fill: #7f8c8d;");
|
|
|
|
|
|
|
|
|
|
Button startButton = new Button("开始练习");
|
|
|
|
|
startButton.setStyle("-fx-background-color: #4CAF50; -fx-text-fill: white; -fx-font-size: 16px; -fx-background-radius: 10;");
|
|
|
|
|
startButton.setPrefSize(220, 55);
|
|
|
|
|
startButton.setOnMouseEntered(e -> startButton.setStyle("-fx-background-color: #45a049; -fx-text-fill: white; -fx-font-size: 16px; -fx-background-radius: 10;"));
|
|
|
|
|
startButton.setOnMouseExited(e -> startButton.setStyle("-fx-background-color: #4CAF50; -fx-text-fill: white; -fx-font-size: 16px; -fx-background-radius: 10;"));
|
|
|
|
|
|
|
|
|
|
Button changePasswordButton = new Button("修改密码");
|
|
|
|
|
changePasswordButton.setStyle("-fx-background-color: #2196F3; -fx-text-fill: white; -fx-font-size: 16px; -fx-background-radius: 10;");
|
|
|
|
|
changePasswordButton.setPrefSize(220, 55);
|
|
|
|
|
changePasswordButton.setOnMouseEntered(e -> changePasswordButton.setStyle("-fx-background-color: #1976D2; -fx-text-fill: white; -fx-font-size: 16px; -fx-background-radius: 10;"));
|
|
|
|
|
changePasswordButton.setOnMouseExited(e -> changePasswordButton.setStyle("-fx-background-color: #2196F3; -fx-text-fill: white; -fx-font-size: 16px; -fx-background-radius: 10;"));
|
|
|
|
|
|
|
|
|
|
Button logoutButton = new Button("退出登录");
|
|
|
|
|
logoutButton.setStyle("-fx-background-color: #f44336; -fx-text-fill: white; -fx-font-size: 16px; -fx-background-radius: 10;");
|
|
|
|
|
logoutButton.setPrefSize(220, 55);
|
|
|
|
|
logoutButton.setOnMouseEntered(e -> logoutButton.setStyle("-fx-background-color: #d32f2f; -fx-text-fill: white; -fx-font-size: 16px; -fx-background-radius: 10;"));
|
|
|
|
|
logoutButton.setOnMouseExited(e -> logoutButton.setStyle("-fx-background-color: #f44336; -fx-text-fill: white; -fx-font-size: 16px; -fx-background-radius: 10;"));
|
|
|
|
|
|
|
|
|
|
startButton.setOnAction(e -> {
|
|
|
|
|
sceneManager.showLevelSelectionView();
|
|
|
|
|
});
|
|
|
|
|
titleSection.getChildren().addAll(titleLabel, welcomeLabel);
|
|
|
|
|
return titleSection;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
changePasswordButton.setOnAction(e -> {
|
|
|
|
|
showChangePasswordDialog();
|
|
|
|
|
});
|
|
|
|
|
/**
|
|
|
|
|
* 创建功能按钮区域.
|
|
|
|
|
*
|
|
|
|
|
* @return VBox 按钮区域布局容器.
|
|
|
|
|
*/
|
|
|
|
|
private VBox createButtonSection() {
|
|
|
|
|
VBox buttonSection = new VBox(15);
|
|
|
|
|
buttonSection.setAlignment(Pos.CENTER);
|
|
|
|
|
|
|
|
|
|
logoutButton.setOnAction(e -> {
|
|
|
|
|
sceneManager.showLoginView();
|
|
|
|
|
});
|
|
|
|
|
Button startButton = createStartButton();
|
|
|
|
|
Button changePasswordButton = createChangePasswordButton();
|
|
|
|
|
Button logoutButton = createLogoutButton();
|
|
|
|
|
|
|
|
|
|
setupButtonActions(startButton, changePasswordButton, logoutButton);
|
|
|
|
|
|
|
|
|
|
menuContent.getChildren().addAll(
|
|
|
|
|
titleLabel, welcomeLabel, startButton,
|
|
|
|
|
changePasswordButton, logoutButton
|
|
|
|
|
buttonSection.getChildren().addAll(
|
|
|
|
|
startButton, changePasswordButton, logoutButton
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return menuContent;
|
|
|
|
|
return buttonSection;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 创建开始练习按钮.
|
|
|
|
|
*
|
|
|
|
|
* @return Button 开始练习按钮对象.
|
|
|
|
|
*/
|
|
|
|
|
private Button createStartButton() {
|
|
|
|
|
Button button = new Button("开始练习");
|
|
|
|
|
button.setStyle("-fx-background-color: #4CAF50; -fx-text-fill: white; "
|
|
|
|
|
+ "-fx-font-size: 16px; -fx-background-radius: 10;");
|
|
|
|
|
button.setPrefSize(220, 55);
|
|
|
|
|
setupButtonHoverEffect(button, "#4CAF50", "#45a049");
|
|
|
|
|
return button;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 创建修改密码按钮.
|
|
|
|
|
*
|
|
|
|
|
* @return Button 修改密码按钮对象.
|
|
|
|
|
*/
|
|
|
|
|
private Button createChangePasswordButton() {
|
|
|
|
|
Button button = new Button("修改密码");
|
|
|
|
|
button.setStyle("-fx-background-color: #2196F3; -fx-text-fill: white; "
|
|
|
|
|
+ "-fx-font-size: 16px; -fx-background-radius: 10;");
|
|
|
|
|
button.setPrefSize(220, 55);
|
|
|
|
|
setupButtonHoverEffect(button, "#2196F3", "#1976D2");
|
|
|
|
|
return button;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 创建退出登录按钮.
|
|
|
|
|
*
|
|
|
|
|
* @return Button 退出登录按钮对象.
|
|
|
|
|
*/
|
|
|
|
|
private Button createLogoutButton() {
|
|
|
|
|
Button button = new Button("退出登录");
|
|
|
|
|
button.setStyle("-fx-background-color: #f44336; -fx-text-fill: white; "
|
|
|
|
|
+ "-fx-font-size: 16px; -fx-background-radius: 10;");
|
|
|
|
|
button.setPrefSize(220, 55);
|
|
|
|
|
setupButtonHoverEffect(button, "#f44336", "#d32f2f");
|
|
|
|
|
return button;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 设置按钮的悬停效果.
|
|
|
|
|
*
|
|
|
|
|
* @param button 需要设置悬停效果的按钮.
|
|
|
|
|
* @param normalColor 正常状态颜色.
|
|
|
|
|
* @param hoverColor 悬停状态颜色.
|
|
|
|
|
*/
|
|
|
|
|
private void setupButtonHoverEffect(Button button, String normalColor,
|
|
|
|
|
String hoverColor) {
|
|
|
|
|
String normalStyle = String.format(
|
|
|
|
|
"-fx-background-color: %s; -fx-text-fill: white; -fx-font-size: 16px; "
|
|
|
|
|
+ "-fx-background-radius: 10;", normalColor);
|
|
|
|
|
String hoverStyle = String.format(
|
|
|
|
|
"-fx-background-color: %s; -fx-text-fill: white; -fx-font-size: 16px; "
|
|
|
|
|
+ "-fx-background-radius: 10;", hoverColor);
|
|
|
|
|
|
|
|
|
|
button.setOnMouseEntered(e -> button.setStyle(hoverStyle));
|
|
|
|
|
button.setOnMouseExited(e -> button.setStyle(normalStyle));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 设置按钮的点击事件.
|
|
|
|
|
*
|
|
|
|
|
* @param startButton 开始练习按钮.
|
|
|
|
|
* @param changePasswordButton 修改密码按钮.
|
|
|
|
|
* @param logoutButton 退出登录按钮.
|
|
|
|
|
*/
|
|
|
|
|
private void setupButtonActions(Button startButton,
|
|
|
|
|
Button changePasswordButton, Button logoutButton) {
|
|
|
|
|
startButton.setOnAction(e -> sceneManager.showLevelSelectionView());
|
|
|
|
|
changePasswordButton.setOnAction(e -> showChangePasswordDialog());
|
|
|
|
|
logoutButton.setOnAction(e -> sceneManager.showLoginView());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取用户名的首字母,用于头像显示.
|
|
|
|
|
*
|
|
|
|
|
* @return String 用户名的首字母大写,如果用户名为空则返回"U".
|
|
|
|
|
*/
|
|
|
|
|
private String getFirstLetter() {
|
|
|
|
|
return currentUsername != null && !currentUsername.isEmpty() ?
|
|
|
|
|
currentUsername.substring(0, 1).toUpperCase() : "U";
|
|
|
|
|
return currentUsername != null && !currentUsername.isEmpty()
|
|
|
|
|
? currentUsername.substring(0, 1).toUpperCase() : "U";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 添加更新用户名的方法
|
|
|
|
|
/**
|
|
|
|
|
* 更新用户名显示.
|
|
|
|
|
*
|
|
|
|
|
* @param username 新的用户名.
|
|
|
|
|
*/
|
|
|
|
|
public void updateUsername(String username) {
|
|
|
|
|
this.currentUsername = username;
|
|
|
|
|
if (usernameLabel != null) {
|
|
|
|
|
@ -170,28 +308,60 @@ public class MainMenuView {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 显示修改密码对话框.
|
|
|
|
|
*/
|
|
|
|
|
private void showChangePasswordDialog() {
|
|
|
|
|
// 创建修改密码对话框
|
|
|
|
|
javafx.scene.control.Dialog<Void> dialog = new javafx.scene.control.Dialog<>();
|
|
|
|
|
javafx.scene.control.Dialog<Void> dialog =
|
|
|
|
|
new javafx.scene.control.Dialog<>();
|
|
|
|
|
dialog.setTitle("修改密码");
|
|
|
|
|
dialog.setHeaderText("请输入密码信息");
|
|
|
|
|
dialog.setGraphic(null); // 移除默认图标
|
|
|
|
|
|
|
|
|
|
// 创建表单
|
|
|
|
|
javafx.scene.layout.GridPane grid = createPasswordForm();
|
|
|
|
|
dialog.getDialogPane().setContent(grid);
|
|
|
|
|
|
|
|
|
|
// 添加按钮
|
|
|
|
|
dialog.getDialogPane().getButtonTypes().addAll(
|
|
|
|
|
javafx.scene.control.ButtonType.OK,
|
|
|
|
|
javafx.scene.control.ButtonType.CANCEL
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
dialog.setResultConverter(dialogButton -> {
|
|
|
|
|
if (dialogButton == javafx.scene.control.ButtonType.OK) {
|
|
|
|
|
handlePasswordChange(grid);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
dialog.showAndWait();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 创建密码修改表单.
|
|
|
|
|
*
|
|
|
|
|
* @return GridPane 密码修改表单布局.
|
|
|
|
|
*/
|
|
|
|
|
private javafx.scene.layout.GridPane createPasswordForm() {
|
|
|
|
|
javafx.scene.layout.GridPane grid = new javafx.scene.layout.GridPane();
|
|
|
|
|
grid.setHgap(15);
|
|
|
|
|
grid.setVgap(15);
|
|
|
|
|
grid.setPadding(new Insets(20, 30, 10, 30));
|
|
|
|
|
|
|
|
|
|
javafx.scene.control.PasswordField oldPassword = new javafx.scene.control.PasswordField();
|
|
|
|
|
javafx.scene.control.PasswordField oldPassword =
|
|
|
|
|
new javafx.scene.control.PasswordField();
|
|
|
|
|
oldPassword.setPromptText("请输入原密码");
|
|
|
|
|
oldPassword.setPrefWidth(200);
|
|
|
|
|
|
|
|
|
|
javafx.scene.control.PasswordField newPassword = new javafx.scene.control.PasswordField();
|
|
|
|
|
newPassword.setPromptText("请输入新密码(密码要6-10位,包含大,小写字母和数字)");
|
|
|
|
|
javafx.scene.control.PasswordField newPassword =
|
|
|
|
|
new javafx.scene.control.PasswordField();
|
|
|
|
|
newPassword.setPromptText("请输入新密码(密码要6-10位,"
|
|
|
|
|
+ "包含大,小写字母和数字)");
|
|
|
|
|
newPassword.setPrefWidth(200);
|
|
|
|
|
|
|
|
|
|
javafx.scene.control.PasswordField confirmPassword = new javafx.scene.control.PasswordField();
|
|
|
|
|
javafx.scene.control.PasswordField confirmPassword =
|
|
|
|
|
new javafx.scene.control.PasswordField();
|
|
|
|
|
confirmPassword.setPromptText("请确认新密码");
|
|
|
|
|
confirmPassword.setPrefWidth(200);
|
|
|
|
|
|
|
|
|
|
@ -202,52 +372,76 @@ public class MainMenuView {
|
|
|
|
|
grid.add(new Label("确认密码:"), 0, 2);
|
|
|
|
|
grid.add(confirmPassword, 1, 2);
|
|
|
|
|
|
|
|
|
|
dialog.getDialogPane().setContent(grid);
|
|
|
|
|
return grid;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 添加按钮
|
|
|
|
|
dialog.getDialogPane().getButtonTypes().addAll(
|
|
|
|
|
javafx.scene.control.ButtonType.OK,
|
|
|
|
|
javafx.scene.control.ButtonType.CANCEL
|
|
|
|
|
);
|
|
|
|
|
/**
|
|
|
|
|
* 处理密码修改逻辑.
|
|
|
|
|
*
|
|
|
|
|
* @param grid 包含密码输入框的表单布局.
|
|
|
|
|
*/
|
|
|
|
|
private void handlePasswordChange(javafx.scene.layout.GridPane grid) {
|
|
|
|
|
javafx.scene.control.PasswordField oldPassword =
|
|
|
|
|
(javafx.scene.control.PasswordField) grid.getChildren().get(1);
|
|
|
|
|
javafx.scene.control.PasswordField newPassword =
|
|
|
|
|
(javafx.scene.control.PasswordField) grid.getChildren().get(3);
|
|
|
|
|
javafx.scene.control.PasswordField confirmPassword =
|
|
|
|
|
(javafx.scene.control.PasswordField) grid.getChildren().get(5);
|
|
|
|
|
|
|
|
|
|
String oldPwd = oldPassword.getText();
|
|
|
|
|
String newPwd = newPassword.getText();
|
|
|
|
|
String confirmPwd = confirmPassword.getText();
|
|
|
|
|
|
|
|
|
|
if (!validatePasswordInput(oldPwd, newPwd, confirmPwd)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dialog.setResultConverter(dialogButton -> {
|
|
|
|
|
if (dialogButton == javafx.scene.control.ButtonType.OK) {
|
|
|
|
|
// 这里可以添加修改密码的逻辑
|
|
|
|
|
String oldPwd = oldPassword.getText();
|
|
|
|
|
String newPwd = newPassword.getText();
|
|
|
|
|
String confirmPwd = confirmPassword.getText();
|
|
|
|
|
|
|
|
|
|
if (oldPwd.isEmpty() || newPwd.isEmpty() || confirmPwd.isEmpty()) {
|
|
|
|
|
showAlert("错误", "请填写所有密码字段!");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
if (!Login.login(currentUsername,oldPwd)){
|
|
|
|
|
showAlert("错误", "原密码错误!");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
if (!newPwd.equals(confirmPwd)) {
|
|
|
|
|
showAlert("错误", "两次输入的新密码不一致!");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
if (!Register.isVaildPassword(newPwd)) {
|
|
|
|
|
showAlert("错误", "密码要6-10位,包含大,小写字母和数字");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
// 调用修改密码的后端逻辑
|
|
|
|
|
if(!ChangePassword.changePassword(currentUsername, confirmPwd)){
|
|
|
|
|
showAlert("错误", "密码修改失败");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
showAlert("成功", "密码修改成功!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
});
|
|
|
|
|
if (!Login.login(currentUsername, oldPwd)) {
|
|
|
|
|
showAlert("错误", "原密码错误!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dialog.showAndWait();
|
|
|
|
|
if (!Register.isVaildPassword(newPwd)) {
|
|
|
|
|
showAlert("错误", "密码要6-10位,包含大,小写字母和数字");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!ChangePassword.changePassword(currentUsername, confirmPwd)) {
|
|
|
|
|
showAlert("错误", "密码修改失败");
|
|
|
|
|
} else {
|
|
|
|
|
showAlert("成功", "密码修改成功!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 验证密码输入.
|
|
|
|
|
*
|
|
|
|
|
* @param oldPwd 原密码.
|
|
|
|
|
* @param newPwd 新密码.
|
|
|
|
|
* @param confirmPwd 确认密码.
|
|
|
|
|
* @return boolean 输入是否有效.
|
|
|
|
|
*/
|
|
|
|
|
private boolean validatePasswordInput(String oldPwd, String newPwd,
|
|
|
|
|
String confirmPwd) {
|
|
|
|
|
if (oldPwd.isEmpty() || newPwd.isEmpty() || confirmPwd.isEmpty()) {
|
|
|
|
|
showAlert("错误", "请填写所有密码字段!");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!newPwd.equals(confirmPwd)) {
|
|
|
|
|
showAlert("错误", "两次输入的新密码不一致!");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 显示提示对话框.
|
|
|
|
|
*
|
|
|
|
|
* @param title 对话框标题.
|
|
|
|
|
* @param message 对话框内容.
|
|
|
|
|
*/
|
|
|
|
|
private void showAlert(String title, String message) {
|
|
|
|
|
Alert alert = new Alert(Alert.AlertType.INFORMATION);
|
|
|
|
|
alert.setTitle(title);
|
|
|
|
|
@ -256,6 +450,11 @@ public class MainMenuView {
|
|
|
|
|
alert.showAndWait();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取当前场景.
|
|
|
|
|
*
|
|
|
|
|
* @return Scene 主菜单界面的场景对象.
|
|
|
|
|
*/
|
|
|
|
|
public Scene getScene() {
|
|
|
|
|
return scene;
|
|
|
|
|
}
|
|
|
|
|
|