From bc0e65dbeb09ec6d969869190540d5898e8ea46e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E5=8D=9A=E6=96=87?= <15549487+FX_YBW@user.noreply.gitee.com> Date: Sat, 11 Oct 2025 23:18:26 +0800 Subject: [PATCH] =?UTF-8?q?v2.2=20=E5=90=8E=E7=AB=AF=E4=BB=A3=E7=A0=81chec?= =?UTF-8?q?kstyle=E6=A3=80=E6=9F=A5=E5=AE=8C=E6=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wsf/mathapp/view/LevelSelectionView.java | 254 +++++------------- .../ybw/mathapp/service/AdvancedCaculate.java | 10 +- .../service/MultipleChoiceGenerator.java | 11 +- .../com/ybw/mathapp/util/EmailService.java | 68 ++--- 4 files changed, 111 insertions(+), 232 deletions(-) diff --git a/src/main/java/com/wsf/mathapp/view/LevelSelectionView.java b/src/main/java/com/wsf/mathapp/view/LevelSelectionView.java index b35c1a3..b9a7092 100644 --- a/src/main/java/com/wsf/mathapp/view/LevelSelectionView.java +++ b/src/main/java/com/wsf/mathapp/view/LevelSelectionView.java @@ -16,10 +16,6 @@ import javafx.scene.text.Font; import javafx.scene.text.FontWeight; import javafx.scene.text.Text; -/** - * 级别选择视图类,提供用户选择题目难度级别的界面. - * 包含小学、初中、高中三个难度级别的选择按钮. - */ public class LevelSelectionView { private Scene scene; private final SceneManager sceneManager; @@ -29,20 +25,12 @@ public class LevelSelectionView { private Label usernameLabel; private Text avatarText; - /** - * 构造函数,初始化级别选择视图. - * - * @param sceneManager 场景管理器,用于界面导航. - */ public LevelSelectionView(SceneManager sceneManager) { this.sceneManager = sceneManager; this.currentUsername = sceneManager.getCurrentUserName(); createScene(); } - /** - * 创建主场景,包含用户信息栏和级别选择内容. - */ private void createScene() { // 创建主容器 VBox mainContainer = new VBox(); @@ -59,45 +47,31 @@ public class LevelSelectionView { 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;"); - // 用户名标签 - 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; - } + userInfoBar.setStyle("-fx-border-color: #e0e0e0; -fx-border-width: 0 0 1 0; -fx-padding: 0 0 15 0;"); - /** - * 创建头像容器,包含圆形头像背景和用户首字母. - * - * @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(); avatarStack.getChildren().addAll(avatarCircle, avatarText); @@ -105,190 +79,101 @@ public class LevelSelectionView { avatarStack.setAlignment(Pos.CENTER); avatarContainer.getChildren().add(avatarStack); - return avatarContainer; - } - /** - * 创建圆形头像背景. - * - * @return Circle 圆形头像背景对象. - */ - private Circle createAvatarCircle() { - Circle avatarCircle = new Circle(22); - avatarCircle.setFill(Color.web("#4CAF50")); // 统一的绿色背景 - avatarCircle.setStroke(Color.WHITE); - avatarCircle.setStrokeWidth(2); + // 用户名标签 + usernameLabel = new Label(currentUsername != null ? currentUsername : "用户"); + usernameLabel.setFont(Font.font("Arial", FontWeight.BOLD, 16)); + usernameLabel.setStyle("-fx-text-fill: #2c3e50;"); - // 添加阴影效果 - avatarCircle.setStyle("-fx-effect: dropshadow(gaussian, rgba(0,0,0,0.2), 5, 0.3, 2, 2);"); - return avatarCircle; + // 间隔 + Region spacer = new Region(); + HBox.setHgrow(spacer, Priority.ALWAYS); + + userInfoBar.getChildren().addAll(avatarContainer, usernameLabel, spacer); + + return userInfoBar; } - /** - * 创建级别选择内容区域,包含标题和级别选择按钮. - * - * @return VBox 级别选择内容区域布局容器. - */ private VBox createSelectionContent() { VBox selectionContent = new VBox(25); selectionContent.setPadding(new Insets(30, 20, 20, 20)); selectionContent.setAlignment(Pos.CENTER); - // 创建标题区域 - VBox titleSection = createTitleSection(); - - // 创建级别按钮区域 - VBox levelButtonsSection = createLevelButtonsSection(); - - // 创建返回按钮 - Button backButton = createBackButton(); - - selectionContent.getChildren().addAll(titleSection, levelButtonsSection, backButton); - - return selectionContent; - } - - /** - * 创建标题区域,包含主标题和副标题. - * - * @return VBox 标题区域布局容器. - */ - private VBox createTitleSection() { - VBox titleSection = new VBox(5); - titleSection.setAlignment(Pos.CENTER); - Label titleLabel = new Label("选择题目级别"); titleLabel.setFont(Font.font("Arial", FontWeight.BOLD, 26)); titleLabel.setStyle("-fx-text-fill: #2c3e50;"); + // 添加副标题 Label subtitleLabel = new Label("请选择适合您的学习级别"); subtitleLabel.setFont(Font.font("Arial", 14)); subtitleLabel.setStyle("-fx-text-fill: #7f8c8d; -fx-padding: 0 0 10 0;"); - titleSection.getChildren().addAll(titleLabel, subtitleLabel); - return titleSection; - } - - /** - * 创建级别按钮区域,包含三个难度级别的选择按钮. - * - * @return VBox 级别按钮区域布局容器. - */ - private VBox createLevelButtonsSection() { - VBox levelButtonsSection = new VBox(15); - levelButtonsSection.setAlignment(Pos.CENTER); - Button primaryButton = createLevelButton("小学题目", "#4CAF50", "#45a049"); Button juniorButton = createLevelButton("初中题目", "#2196F3", "#1976D2"); Button seniorButton = createLevelButton("高中题目", "#9C27B0", "#7B1FA2"); - setupLevelButtonAction(primaryButton, "小学"); - setupLevelButtonAction(juniorButton, "初中"); - setupLevelButtonAction(seniorButton, "高中"); + Button backButton = new Button("返回主菜单"); + backButton.setStyle("-fx-background-color: #95a5a6; -fx-text-fill: white; -fx-font-size: 14px; -fx-background-radius: 8; -fx-padding: 8 20;"); + backButton.setPrefSize(180, 45); + backButton.setOnMouseEntered(e -> backButton.setStyle("-fx-background-color: #7f8c8d; -fx-text-fill: white; -fx-font-size: 14px; -fx-background-radius: 8; -fx-padding: 8 20;")); + backButton.setOnMouseExited(e -> backButton.setStyle("-fx-background-color: #95a5a6; -fx-text-fill: white; -fx-font-size: 14px; -fx-background-radius: 8; -fx-padding: 8 20;")); - levelButtonsSection.getChildren().addAll(primaryButton, juniorButton, seniorButton); - return levelButtonsSection; - } + primaryButton.setOnAction(e -> { + String selectedLevel = "小学"; + sceneManager.getQuestionCountView().setLevel(selectedLevel); + sceneManager.showQuestionCountView(); + }); - /** - * 设置级别按钮的点击事件. - * - * @param button 级别按钮. - * @param level 对应的难度级别. - */ - private void setupLevelButtonAction(Button button, String level) { - button.setOnAction(e -> { - sceneManager.getQuestionCountView().setLevel(level); + juniorButton.setOnAction(e -> { + String selectedLevel = "初中"; + sceneManager.getQuestionCountView().setLevel(selectedLevel); sceneManager.showQuestionCountView(); }); - } - /** - * 创建返回按钮. - * - * @return Button 返回主菜单按钮. - */ - private Button createBackButton() { - Button backButton = new Button("返回主菜单"); - backButton.setStyle("-fx-background-color: #95a5a6; -fx-text-fill: " - + "white; -fx-font-size: 14px; -fx-background-radius: 8; -fx-padding: 8 20;"); - backButton.setPrefSize(180, 45); - setupButtonHoverEffect(backButton, "#95a5a6", "#7f8c8d"); - backButton.setOnAction(e -> sceneManager.showMainMenuView()); + seniorButton.setOnAction(e -> { + String selectedLevel = "高中"; + sceneManager.getQuestionCountView().setLevel(selectedLevel); + sceneManager.showQuestionCountView(); + }); - return backButton; + backButton.setOnAction(e -> { + sceneManager.showMainMenuView(); + }); + + selectionContent.getChildren().addAll( + titleLabel, subtitleLabel, primaryButton, juniorButton, seniorButton, backButton + ); + + return selectionContent; } - /** - * 创建级别选择按钮. - * - * @param text 按钮显示文本. - * @param color 按钮正常状态颜色. - * @param hoverColor 按钮悬停状态颜色. - * @return Button 配置好的级别选择按钮. - */ private Button createLevelButton(String text, String color, String hoverColor) { 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: dropshadow(gaussian, rgba(0,0,0,0.2), 8, 0.3, 2, 2);", + "-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: dropshadow(gaussian, rgba(0,0,0,0.2), 8, 0.3, 2, 2);", color )); button.setPrefSize(220, 60); - - setupButtonHoverEffect(button, color, hoverColor); - + 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: 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: dropshadow(gaussian, rgba(0,0,0,0.2), 8, 0.3, 2, 2);", + color + ))); 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: %s;" - + " -fx-background-radius: %s; -fx-padding: %s; -fx-effect: " - + "dropshadow(gaussian, rgba(0,0,0,0.2), 8, 0.3, 2, 2);", - normalColor, - button.getStyle().contains("16px") ? "16px" : "14px", - button.getStyle().contains("12") ? "12" : "8", - button.getStyle().contains("12 30") ? "12 30" : "8 20" - ); - - String hoverStyle = String.format( - "-fx-background-color: %s; -fx-text-fill: white; -fx-font-size: %s;" - + " -fx-background-radius: %s; -fx-padding: %s; -fx-effect:" - + " dropshadow(gaussian, rgba(0,0,0,0.3), 10, 0.4, 3, 3);", - hoverColor, - button.getStyle().contains("16px") ? "16px" : "14px", - button.getStyle().contains("12") ? "12" : "8", - button.getStyle().contains("12 30") ? "12 30" : "8 20" - ); - - button.setOnMouseEntered(e -> button.setStyle(hoverStyle)); - button.setOnMouseExited(e -> button.setStyle(normalStyle)); - } - - /** - * 获取用户名的首字母,用于头像显示. - * - * @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) { @@ -299,11 +184,6 @@ public class LevelSelectionView { } } - /** - * 获取当前场景. - * - * @return Scene 级别选择界面的场景对象. - */ public Scene getScene() { return scene; } diff --git a/src/main/java/com/ybw/mathapp/service/AdvancedCaculate.java b/src/main/java/com/ybw/mathapp/service/AdvancedCaculate.java index 74240b9..2f41901 100644 --- a/src/main/java/com/ybw/mathapp/service/AdvancedCaculate.java +++ b/src/main/java/com/ybw/mathapp/service/AdvancedCaculate.java @@ -20,8 +20,8 @@ import java.util.Stack; * *

例如: *

* @@ -134,9 +134,9 @@ public class AdvancedCaculate { private static void handleBasicOperator(String token, Stack numberStack, Stack operatorStack) { // 处理四则运算符,遵循优先级 - while (!operatorStack.isEmpty() && - !operatorStack.peek().equals("(") && - PRECEDENCE.get(token) <= PRECEDENCE.getOrDefault(operatorStack.peek(), 0)) { + while (!operatorStack.isEmpty() + && !operatorStack.peek().equals("(") + && PRECEDENCE.get(token) <= PRECEDENCE.getOrDefault(operatorStack.peek(), 0)) { processOperator(numberStack, operatorStack.pop()); } operatorStack.push(token); diff --git a/src/main/java/com/ybw/mathapp/service/MultipleChoiceGenerator.java b/src/main/java/com/ybw/mathapp/service/MultipleChoiceGenerator.java index ab31c1a..d84b603 100644 --- a/src/main/java/com/ybw/mathapp/service/MultipleChoiceGenerator.java +++ b/src/main/java/com/ybw/mathapp/service/MultipleChoiceGenerator.java @@ -69,7 +69,7 @@ public class MultipleChoiceGenerator { // 如果无法生成不重复的基础题目,可能基础生成器的可能组合已用尽 break; // 退出循环 } - QuestionWithOptions mcq = generateSingleMCQ(baseQuestion); + QuestionWithOptions mcq = generateSingleMcq(baseQuestion); if (mcq != null) { mcQuestions.add(mcq); seenQuestionTexts.add(baseQuestion); // 添加成功生成的题干 @@ -105,7 +105,7 @@ public class MultipleChoiceGenerator { * @param baseQuestion 基础题干字符串,例如 "3 + 5 = ?" * @return 生成的选择题对象,如果计算或生成选项失败则返回 null */ - private QuestionWithOptions generateSingleMCQ(String baseQuestion) { + private QuestionWithOptions generateSingleMcq(String baseQuestion) { try { // 从基础题干中提取表达式部分,例如 "3 + 5 = ?" -> "3 + 5" String expression = baseQuestion.substring(0, baseQuestion.lastIndexOf(" =")).trim(); @@ -165,7 +165,6 @@ public class MultipleChoiceGenerator { } if (wrongAnswers.size() < numWrongOptions) { - // System.out.println("Warning: Could not generate enough distinct wrong answers for: " + correctAnswer); return null; // 无法生成足够选项 } @@ -197,7 +196,7 @@ public class MultipleChoiceGenerator { List tokens = new ArrayList<>(); int i = 0; while (i < expression.length()) { - String token = _findNextToken(expression, i); + String token = findNextToken(expression, i); if (token != null) { tokens.add(token); i += token.length(); @@ -220,8 +219,7 @@ public class MultipleChoiceGenerator { * @param startPos 起始查找位置 * @return 找到的 token,如果未找到则返回 null */ - private String _findNextToken(String expression, int startPos) { - String[] advancedOps = {"平方", "开根号", "sin", "cos", "tan"}; + private String findNextToken(String expression, int startPos) { char c = expression.charAt(startPos); if (Character.isWhitespace(c)) { @@ -240,6 +238,7 @@ public class MultipleChoiceGenerator { return expression.substring(startPos, j); } + String[] advancedOps = {"平方", "开根号", "sin", "cos", "tan"}; // 检查多字符运算符 for (String op : advancedOps) { if (expression.startsWith(op, startPos)) { diff --git a/src/main/java/com/ybw/mathapp/util/EmailService.java b/src/main/java/com/ybw/mathapp/util/EmailService.java index 5a3451d..956d5de 100644 --- a/src/main/java/com/ybw/mathapp/util/EmailService.java +++ b/src/main/java/com/ybw/mathapp/util/EmailService.java @@ -111,38 +111,38 @@ public class EmailService { * @return HTML格式的邮件正文字符串 */ private static String createEmailContent(String code) { - return "" + - "" + - "" + - "" + - "" + - "" + - "" + - "
" + - "
" + - "

用户注册验证码

" + - "
" + - "
" + - "

您好!

" + - "

您正在注册账户,验证码如下:

" + - "
" + code + "
" + - "

验证码有效期为 " + EmailConfig.CODE_EXPIRY_MINUTES + " 分钟,请勿泄露给他人。

" + - "

如果这不是您本人的操作,请忽略此邮件。

" + - "
" + - "" + - "
" + - "" + - ""; + return "" + + "" + + "" + + "" + + "" + + "" + + "" + + "
" + + "
" + + "

用户注册验证码

" + + "
" + + "
" + + "

您好!

" + + "

您正在注册账户,验证码如下:

" + + "
" + code + "
" + + "

验证码有效期为 " + EmailConfig.CODE_EXPIRY_MINUTES + " 分钟,请勿泄露给他人。

" + + "

如果这不是您本人的操作,请忽略此邮件。

" + + "
" + + "" + + "
" + + "" + + ""; } /** @@ -178,8 +178,8 @@ public class EmailService { while (iterator.hasNext()) { Map.Entry entry = iterator.next(); - if (currentTime - entry.getValue().timestamp > - EmailConfig.CODE_EXPIRY_MINUTES * 60 * 1000) { + if (currentTime - entry.getValue().timestamp + > EmailConfig.CODE_EXPIRY_MINUTES * 60 * 1000) { iterator.remove(); } }