diff --git a/images/default-avatar.png b/images/default-avatar.png new file mode 100644 index 0000000..e7fe7f4 Binary files /dev/null and b/images/default-avatar.png differ diff --git a/src/main/java/com/wsf/mathapp/controller/SceneManager.java b/src/main/java/com/wsf/mathapp/controller/SceneManager.java index edbc218..5bbfda7 100644 --- a/src/main/java/com/wsf/mathapp/controller/SceneManager.java +++ b/src/main/java/com/wsf/mathapp/controller/SceneManager.java @@ -30,45 +30,54 @@ public class SceneManager { } public void showLoginView() { + System.out.println("切换到登录界面"); primaryStage.setScene(loginView.getScene()); primaryStage.show(); } public void showRegisterView() { + System.out.println("切换到注册界面"); primaryStage.setScene(registerView.getScene()); primaryStage.show(); } public void showMainMenuView() { + System.out.println("切换到主菜单界面"); // 在显示主菜单前更新用户名 if (mainMenuView != null) { mainMenuView.updateUsername(currentUserName); } - if (mainMenuView != null) { - primaryStage.setScene(mainMenuView.getScene()); - } + primaryStage.setScene(mainMenuView.getScene()); + primaryStage.show(); // 添加这行 } public void showLevelSelectionView() { + System.out.println("切换到级别选择界面"); // 在显示级别选择界面前更新用户名 if (levelSelectionView != null) { levelSelectionView.updateUsername(currentUserName); } - if (levelSelectionView != null) { - primaryStage.setScene(levelSelectionView.getScene()); - } + primaryStage.setScene(levelSelectionView.getScene()); + primaryStage.show(); // 添加这行 } + public void showQuestionCountView() { + System.out.println("切换到题目数量选择界面"); primaryStage.setScene(questionCountView.getScene()); + primaryStage.show(); // 添加这行 } public void showQuizView() { + System.out.println("切换到答题界面"); primaryStage.setScene(quizView.getScene()); + primaryStage.show(); // 添加这行 } public void showResultView(double score) { + System.out.println("切换到结果界面,分数: " + score); resultView.setScore(score); primaryStage.setScene(resultView.getScene()); + primaryStage.show(); // 添加这行 } // Getter methods for views @@ -79,6 +88,13 @@ public class SceneManager { public QuestionCountView getQuestionCountView() { return questionCountView; } public QuizView getQuizView() { return quizView; } public ResultView getResultView() { return resultView; } - public void setCurrentUserName(String currentUserName){ this.currentUserName = currentUserName;} - public String getCurrentUserName(){return this.currentUserName;} + + public void setCurrentUserName(String currentUserName) { + this.currentUserName = currentUserName; + System.out.println("设置当前用户名: " + currentUserName); + } + + public String getCurrentUserName() { + return this.currentUserName; + } } \ No newline at end of file diff --git a/src/main/java/com/wsf/mathapp/view/LevelSelectionView.java b/src/main/java/com/wsf/mathapp/view/LevelSelectionView.java index 94f675e..b9a7092 100644 --- a/src/main/java/com/wsf/mathapp/view/LevelSelectionView.java +++ b/src/main/java/com/wsf/mathapp/view/LevelSelectionView.java @@ -65,7 +65,7 @@ public class LevelSelectionView { avatarCircle.setStrokeWidth(2); // 添加阴影效果 - avatarCircle.setStyle("-fx-effect: drop shadow(gaussian, rgba(0,0,0,0.2), 5, 0.3, 2, 2);"); + avatarCircle.setStyle("-fx-effect: dropshadow(gaussian, rgba(0,0,0,0.2), 5, 0.3, 2, 2);"); // 添加首字母文本 avatarText = new Text(getFirstLetter()); @@ -151,18 +151,18 @@ public class LevelSelectionView { Button button = new Button(text); button.setStyle(String.format( "-fx-background-color: %s; -fx-text-fill: white; -fx-font-size: 16px; -fx-font-weight: bold; " + - "-fx-background-radius: 12; -fx-padding: 12 30; -fx-effect: drop shadow(gaussian, rgba(0,0,0,0.2), 8, 0.3, 2, 2);", + "-fx-background-radius: 12; -fx-padding: 12 30; -fx-effect: dropshadow(gaussian, rgba(0,0,0,0.2), 8, 0.3, 2, 2);", color )); button.setPrefSize(220, 60); button.setOnMouseEntered(e -> button.setStyle(String.format( "-fx-background-color: %s; -fx-text-fill: white; -fx-font-size: 16px; -fx-font-weight: bold; " + - "-fx-background-radius: 12; -fx-padding: 12 30; -fx-effect: drop shadow(gaussian, rgba(0,0,0,0.3), 10, 0.4, 3, 3);", + "-fx-background-radius: 12; -fx-padding: 12 30; -fx-effect: dropshadow(gaussian, rgba(0,0,0,0.3), 10, 0.4, 3, 3);", hoverColor ))); button.setOnMouseExited(e -> button.setStyle(String.format( "-fx-background-color: %s; -fx-text-fill: white; -fx-font-size: 16px; -fx-font-weight: bold; " + - "-fx-background-radius: 12; -fx-padding: 12 30; -fx-effect: drop shadow(gaussian, rgba(0,0,0,0.2), 8, 0.3, 2, 2);", + "-fx-background-radius: 12; -fx-padding: 12 30; -fx-effect: dropshadow(gaussian, rgba(0,0,0,0.2), 8, 0.3, 2, 2);", color ))); return button; diff --git a/src/main/java/com/wsf/mathapp/view/MainMenuView.java b/src/main/java/com/wsf/mathapp/view/MainMenuView.java index 2734eee..8953009 100644 --- a/src/main/java/com/wsf/mathapp/view/MainMenuView.java +++ b/src/main/java/com/wsf/mathapp/view/MainMenuView.java @@ -69,7 +69,7 @@ public class MainMenuView { avatarCircle.setStrokeWidth(2); // 添加阴影效果 - avatarCircle.setStyle("-fx-effect: drop shadow(gaussian, rgba(0,0,0,0.2), 5, 0.3, 2, 2);"); + avatarCircle.setStyle("-fx-effect: dropshadow(gaussian, rgba(0,0,0,0.2), 5, 0.3, 2, 2);"); // 添加首字母文本 avatarText = new Text(getFirstLetter()); @@ -230,8 +230,12 @@ public class MainMenuView { } // 调用修改密码的后端逻辑 - ChangePassword.changePassword(currentUsername, confirmPwd); - showAlert("成功", "密码修改成功!"); + if(!ChangePassword.changePassword(currentUsername, confirmPwd)){ + showAlert("错误", "密码修改失败"); + } + else{ + showAlert("成功", "密码修改成功!"); + } } return null; }); diff --git a/src/main/java/com/wsf/mathapp/view/ResultView.java b/src/main/java/com/wsf/mathapp/view/ResultView.java index a1bb0c8..5276044 100644 --- a/src/main/java/com/wsf/mathapp/view/ResultView.java +++ b/src/main/java/com/wsf/mathapp/view/ResultView.java @@ -95,7 +95,7 @@ public class ResultView { private Image createTextAvatar() { // 创建一个简单的文本头像(使用首字母) - String firstLetter = currentUsername.length() > 0 ? + String firstLetter = !currentUsername.isEmpty() ? currentUsername.substring(0, 1).toUpperCase() : "U"; // 这里可以创建一个包含文本的图像,但为了简单起见,我们使用CSS样式 diff --git a/src/main/java/com/ybw/mathapp/LoginAndRegister.java b/src/main/java/com/ybw/mathapp/LoginAndRegister.java deleted file mode 100644 index d71d548..0000000 --- a/src/main/java/com/ybw/mathapp/LoginAndRegister.java +++ /dev/null @@ -1,132 +0,0 @@ -package com.ybw.mathapp; - -// UserService.java -import com.ybw.mathapp.entity.User; -import com.ybw.mathapp.service.EmailService; -import com.ybw.mathapp.util.LoginFileUtils; -import java.util.Scanner; -import java.util.regex.Pattern; - -public class LoginAndRegister { - private static Scanner scanner = new Scanner(System.in); - - // UserService.java 中的注册方法更新 - public static boolean register() { - System.out.println("\n=== 用户注册 ==="); - - // 输入邮箱 - System.out.print("请输入邮箱地址: "); - String email = scanner.nextLine().trim(); - - if (!isValidEmail(email)) { - return false; - } - - if (LoginFileUtils.isEmailRegistered(email)) { - System.out.println("该邮箱已注册,请直接登录!"); - return false; - } - - // 发送、验证验证码 - if (!sendAndVerifyCode(email)) { - return false; - } - - // 设置密码(其余代码保持不变) - System.out.print("请输入密码: "); - String password1 = scanner.nextLine(); - System.out.print("请再次输入密码: "); - String password2 = scanner.nextLine(); - if(!isVaildPassword(password1, password2)) { - return false; - } - - User user = new User(email, password1); - LoginFileUtils.saveUser(user); - System.out.println("注册成功!您可以使用邮箱和密码登录了。"); - return true; - } - - // 登录流程 - public static boolean login() { - System.out.println("\n=== 用户登录 ==="); - - System.out.print("请输入邮箱: "); - String email = scanner.nextLine().trim(); - - System.out.print("请输入密码: "); - String password = scanner.nextLine(); - - if (LoginFileUtils.validateUser(email, password)) { - System.out.println("登录成功!欢迎回来," + email); - return true; - } else { - System.out.println("邮箱或密码错误!"); - return false; - } - } - - // - /** - * 邮箱格式验证 - * @param email 待验证的邮箱地址 - * @return true表示邮箱格式正确,false表示邮箱格式错误 - */ - private static boolean isValidEmail(String email) { - if (email.isEmpty()) { - System.out.println("邮箱地址不能为空!"); - return false; - } - if (!(email.contains("@") && email.contains("."))) { - System.out.println("邮箱格式不正确!"); - return false; - } - return true; - } - - /** - * 密码格式验证 - * @param password1 第一次输入的密码 - * @param password2 第二次输入的密码 - * @return true表示符合要求,false表示不符合 - */ - public static boolean isVaildPassword(String password1, String password2) { - if (password1 == null || password1.length() < 6 || password1.length() > 10) { - return false; - } - - // 使用正则表达式验证:长度6-10,只包含字母数字,且包含大小写字母和数字 - String regex = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)[a-zA-Z\\d]{6,10}$"; - if (!Pattern.matches(regex, password1)) { - return false; - } - - System.out.print("请再次输入密码: "); - if (!password1.equals(password2)) { - System.out.println("两次输入的密码不一致!"); - return false; - } - return true; - } - - public static boolean sendAndVerifyCode(String email) { - // 发送真实邮件验证码 - String verificationCode = EmailService.generateVerificationCode(); - System.out.println("正在发送验证码邮件,请稍候..."); - - if (!EmailService.sendVerificationCode(email, verificationCode)) { - System.out.println("发送验证码失败,请检查邮箱配置或稍后重试!"); - return false; - } - - // 验证验证码 - System.out.print("请输入收到的验证码: "); - String inputCode = scanner.nextLine().trim(); - - if (!EmailService.verifyCode(email, inputCode)) { - System.out.println("验证码错误或已过期!"); - return false; - } - return true; - } -}