完善格式 #7

Merged
hnu202326010207 merged 3 commits from yinhaoming_branch into develop 5 months ago

@ -74,7 +74,7 @@
<artifactId>javafx-maven-plugin</artifactId>
<version>${javafx.maven.plugin.version}</version>
<configuration>
<mainClass>com.personalproject.ui.MathExamGUI</mainClass>
<mainClass>com.personalproject.ui.MathExamGui</mainClass>
<!-- Specify required JavaFX modules -->
<options>
<option>--add-modules</option>
@ -86,7 +86,7 @@
<!-- Default execution for run goal -->
<id>default-cli</id>
<configuration>
<mainClass>com.personalproject.ui.MathExamGUI</mainClass>
<mainClass>com.personalproject.ui.MathExamGui</mainClass>
</configuration>
</execution>
</executions>
@ -107,7 +107,7 @@
<configuration>
<archive>
<manifest>
<mainClass>com.personalproject.ui.MathExamGUI</mainClass>
<mainClass>com.personalproject.ui.MathExamGui</mainClass>
</manifest>
</archive>
</configuration>
@ -127,7 +127,7 @@
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.personalproject.ui.MathExamGUI</mainClass>
<mainClass>com.personalproject.ui.MathExamGui</mainClass>
</transformer>
</transformers>
<!-- Include all JavaFX modules in the fat JAR -->

@ -1,10 +1,9 @@
package com.personalproject;
import com.personalproject.ui.MathExamGUI;
import com.personalproject.ui.MathExamGui;
/**
* .
* JavaFX GUI
* . JavaFX GUI.
*/
public final class MathExamApplication {
@ -15,6 +14,6 @@ public final class MathExamApplication {
*/
public static void main(String[] args) {
// 启动JavaFX应用程序
MathExamGUI.main(args);
MathExamGui.main(args);
}
}
}

@ -26,6 +26,9 @@ public final class AccountRepository {
private final Map<String, UserAccount> accounts = new ConcurrentHashMap<>();
/**
* .
*/
public AccountRepository() {
loadAccounts();
}
@ -54,7 +57,7 @@ public final class AccountRepository {
}
/**
* 使
* 使.
*
* @param username
* @param email
@ -82,7 +85,8 @@ public final class AccountRepository {
return false;
}
LocalDateTime registrationDate = existing != null ? existing.registrationDate() : LocalDateTime.now();
LocalDateTime registrationDate =
existing != null ? existing.registrationDate() : LocalDateTime.now();
UserAccount account = new UserAccount(
normalizedUsername,
normalizedEmail,
@ -97,7 +101,7 @@ public final class AccountRepository {
}
/**
*
* .
*
* @param username
* @param password
@ -126,7 +130,7 @@ public final class AccountRepository {
}
/**
*
* .
*
* @param username
* @param oldPassword
@ -161,7 +165,7 @@ public final class AccountRepository {
}
/**
* 便
* 便.
*
* @param username
*/
@ -178,7 +182,7 @@ public final class AccountRepository {
}
/**
*
* .
*
* @param username
* @return true false
@ -191,7 +195,7 @@ public final class AccountRepository {
}
/**
*
* .
*
* @param username
* @return Optional

@ -26,7 +26,7 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicReference;
/**
*
* .
*/
public final class EmailService {
@ -46,7 +46,7 @@ public final class EmailService {
}
/**
*
* .
*
* @return
*/
@ -59,7 +59,7 @@ public final class EmailService {
}
/**
*
* .
*
* @param email
* @param registrationCode
@ -79,7 +79,7 @@ public final class EmailService {
}
/**
* 便
* 便.
*
* @param email
* @return
@ -92,7 +92,7 @@ public final class EmailService {
}
/**
*
* .
*
* @param email
* @return true false
@ -134,9 +134,9 @@ public final class EmailService {
}
String username = require(properties, "mail.username");
String password = require(properties, "mail.password");
String from = properties.getProperty("mail.from", username);
String subject = properties.getProperty("mail.subject", DEFAULT_SUBJECT);
final String password = require(properties, "mail.password");
final String from = properties.getProperty("mail.from", username);
final String subject = properties.getProperty("mail.subject", DEFAULT_SUBJECT);
Properties smtpProperties = new Properties();
for (Map.Entry<Object, Object> entry : properties.entrySet()) {
@ -194,7 +194,7 @@ public final class EmailService {
String sanitizedEmail = sanitizeEmail(email);
String timestamp = DATE_TIME_FORMATTER.format(LocalDateTime.now());
Path messageFile = OUTBOX_DIRECTORY.resolve(sanitizedEmail + "_" + timestamp + ".txt");
final Path messageFile = OUTBOX_DIRECTORY.resolve(sanitizedEmail + "_" + timestamp + ".txt");
StringBuilder content = new StringBuilder();
content.append("收件人: ").append(email).append(System.lineSeparator());
content.append("注册码: ").append(registrationCode).append(System.lineSeparator());
@ -226,5 +226,6 @@ public final class EmailService {
String password,
String from,
String subject) {
}
}

@ -3,7 +3,7 @@ package com.personalproject.auth;
import java.util.regex.Pattern;
/**
*
* .
*/
public final class PasswordValidator {
@ -15,7 +15,7 @@ public final class PasswordValidator {
}
/**
*
* .
* - 6-10
* -
* -

@ -15,7 +15,7 @@ public record UserAccount(
boolean isRegistered) {
/**
* 使
* 使.
*
* @param username
* @param email

@ -144,7 +144,7 @@ public final class MathLearningController {
}
/**
*
* .
*
* @param username
* @return Optional

@ -2,7 +2,6 @@ package com.personalproject.generator;
import com.personalproject.model.QuizQuestion;
import com.personalproject.service.MathExpressionEvaluator;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashSet;
@ -78,7 +77,7 @@ public final class PrimaryQuestionGenerator implements QuestionGenerator, QuizQu
}
/**
*
* .
*/
private List<String> generateOptions(double correctAnswer, Random random) {
String correctOption = formatOption(correctAnswer);

@ -6,7 +6,7 @@ import java.util.Collections;
import java.util.List;
/**
*
* .
*/
public final class ExamSession {
@ -18,7 +18,7 @@ public final class ExamSession {
private int currentQuestionIndex;
/**
*
* .
*
* @param username
* @param difficultyLevel
@ -45,7 +45,7 @@ public final class ExamSession {
}
/**
*
* .
*
* @return
*/
@ -54,7 +54,7 @@ public final class ExamSession {
}
/**
*
* .
*
* @return
*/
@ -63,7 +63,7 @@ public final class ExamSession {
}
/**
*
* .
*
* @return
*/
@ -72,7 +72,7 @@ public final class ExamSession {
}
/**
*
* .
*
* @return -1
*/
@ -81,7 +81,7 @@ public final class ExamSession {
}
/**
*
* .
*
* @return
*/
@ -90,7 +90,7 @@ public final class ExamSession {
}
/**
*
* .
*
* @param answerIndex
*/
@ -106,7 +106,7 @@ public final class ExamSession {
}
/**
*
* .
*
* @return true false
*/
@ -119,7 +119,7 @@ public final class ExamSession {
}
/**
*
* .
*
* @return true false
*/
@ -132,7 +132,7 @@ public final class ExamSession {
}
/**
*
* .
*
* @return true false
*/
@ -141,7 +141,7 @@ public final class ExamSession {
}
/**
*
* .
*
* @return
*/
@ -153,7 +153,7 @@ public final class ExamSession {
}
/**
*
* .
*
* @param questionIndex
* @return -1
@ -166,7 +166,7 @@ public final class ExamSession {
}
/**
*
* .
*
* @return 0-100
*/
@ -183,7 +183,7 @@ public final class ExamSession {
}
/**
*
* .
*
* @return
*/
@ -192,7 +192,7 @@ public final class ExamSession {
}
/**
*
* .
*
* @param questionIndex
* @return true false
@ -205,7 +205,7 @@ public final class ExamSession {
}
/**
*
* .
*
* @return
*/
@ -214,7 +214,7 @@ public final class ExamSession {
}
/**
*
* .
*
* @return
*/
@ -231,14 +231,14 @@ public final class ExamSession {
}
/**
*
* .
*
* @return
*/
public int getIncorrectAnswersCount() {
int totalAnswered = 0;
int correctCount = 0;
for (int i = 0; i < questions.size(); i++) {
int userAnswer = userAnswers.get(i);
if (userAnswer != -1) {
@ -249,7 +249,7 @@ public final class ExamSession {
}
}
}
return totalAnswered - correctCount;
}
}

@ -3,7 +3,7 @@ package com.personalproject.model;
import java.util.List;
/**
*
* .
*/
public final class QuizQuestion {
@ -12,7 +12,7 @@ public final class QuizQuestion {
private final int correctAnswerIndex;
/**
*
* .
*
* @param questionText
* @param options
@ -35,7 +35,7 @@ public final class QuizQuestion {
}
/**
*
* .
*
* @return
*/
@ -44,7 +44,7 @@ public final class QuizQuestion {
}
/**
*
* .
*
* @return
*/
@ -53,7 +53,7 @@ public final class QuizQuestion {
}
/**
*
* .
*
* @return
*/
@ -62,7 +62,7 @@ public final class QuizQuestion {
}
/**
*
* .
*
* @param answerIndex
* @return true false

@ -31,7 +31,7 @@ public final class ExamService {
*
* @param generatorMap
* @param questionGenerationService
* @param questionStorageService
* @param questionStorageService
*/
public ExamService(
Map<DifficultyLevel, QuestionGenerator> generatorMap,

@ -7,7 +7,7 @@ import java.util.function.DoubleUnaryOperator;
import java.util.regex.Pattern;
/**
*
* .
*/
public final class MathExpressionEvaluator {
@ -33,7 +33,7 @@ public final class MathExpressionEvaluator {
}
/**
*
* .
*
* @param expression
* @return
@ -60,7 +60,7 @@ public final class MathExpressionEvaluator {
}
/**
*
* .
*
* @param expression
* @return
@ -120,7 +120,7 @@ public final class MathExpressionEvaluator {
}
/**
*
* .
*
* @param c
* @return true false
@ -134,7 +134,7 @@ public final class MathExpressionEvaluator {
}
/**
* 使
* 使.
*
* @param tokens
* @return
@ -182,7 +182,7 @@ public final class MathExpressionEvaluator {
}
/**
*
* .
*
* @param postfix
* @return
@ -204,7 +204,8 @@ public final class MathExpressionEvaluator {
values.push(result);
} else if (isFunction(token)) {
if (values.isEmpty()) {
throw new IllegalArgumentException("Invalid expression: insufficient operands for function");
throw new IllegalArgumentException(
"Invalid expression: insufficient operands for function");
}
double value = values.pop();
values.push(applyFunction(token, value));
@ -221,7 +222,7 @@ public final class MathExpressionEvaluator {
}
/**
*
* .
*
* @param a
* @param b
@ -257,7 +258,7 @@ public final class MathExpressionEvaluator {
}
/**
*
* .
*
* @param token
* @return true false

@ -169,7 +169,7 @@ public final class MathLearningService {
}
/**
*
* .
*
* @param username
* @return Optional

@ -187,7 +187,7 @@ public final class RegistrationService {
}
/**
*
* .
*
* @param username
* @return Optional

@ -1,8 +1,5 @@
package com.personalproject.ui;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.stage.Stage;
import com.personalproject.controller.MathLearningController;
import com.personalproject.generator.HighSchoolQuestionGenerator;
import com.personalproject.generator.MiddleSchoolQuestionGenerator;
@ -11,15 +8,16 @@ import com.personalproject.generator.QuestionGenerator;
import com.personalproject.model.DifficultyLevel;
import com.personalproject.service.QuestionGenerationService;
import com.personalproject.ui.scenes.LoginScene;
import java.util.EnumMap;
import java.util.Map;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.stage.Stage;
/**
* JavaFX
*
* JavaFX . .
*/
public final class MathExamGUI extends Application {
public final class MathExamGui extends Application {
private MathLearningController controller;
@ -30,22 +28,23 @@ public final class MathExamGUI extends Application {
generatorMap.put(DifficultyLevel.PRIMARY, new PrimaryQuestionGenerator());
generatorMap.put(DifficultyLevel.MIDDLE, new MiddleSchoolQuestionGenerator());
generatorMap.put(DifficultyLevel.HIGH, new HighSchoolQuestionGenerator());
QuestionGenerationService questionGenerationService = new QuestionGenerationService(generatorMap);
QuestionGenerationService questionGenerationService = new QuestionGenerationService(
generatorMap);
this.controller = new MathLearningController(generatorMap, questionGenerationService);
// 配置主舞台
primaryStage.setTitle("数学学习软件");
// 从登录界面开始
LoginScene loginScene = new LoginScene(primaryStage, controller);
Scene scene = new Scene(loginScene, 600, 400);
primaryStage.setScene(scene);
primaryStage.show();
}
/**
* JavaFX
* JavaFX .
*
* @param args
*/

@ -1,18 +1,24 @@
package com.personalproject.ui.scenes;
import com.personalproject.controller.MathLearningController;
import com.personalproject.ui.views.MainMenuView;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.stage.Stage;
import com.personalproject.controller.MathLearningController;
import com.personalproject.ui.views.MainMenuView;
import com.personalproject.ui.scenes.RegistrationScene;
/**
*
* .
*/
public class LoginScene extends BorderPane {
@ -24,79 +30,79 @@ public class LoginScene extends BorderPane {
private Button registerButton;
/**
* LoginScene
* LoginScene .
*
* @param primaryStage
* @param controller
* @param controller
*/
public LoginScene(Stage primaryStage, MathLearningController controller) {
this.primaryStage = primaryStage;
this.controller = controller;
initializeUI();
initializeUi();
}
/**
*
* .
*/
private void initializeUI() {
private void initializeUi() {
// 创建主布局
VBox mainLayout = new VBox(15);
mainLayout.setAlignment(Pos.CENTER);
mainLayout.setPadding(new Insets(20));
// 标题
Label titleLabel = new Label("数学学习软件");
final Label titleLabel = new Label("数学学习软件");
titleLabel.setFont(Font.font("System", FontWeight.BOLD, 24));
// 登录表单
GridPane loginForm = new GridPane();
loginForm.setHgap(10);
loginForm.setVgap(10);
loginForm.setAlignment(Pos.CENTER);
Label usernameLabel = new Label("用户名:");
final Label usernameLabel = new Label("用户名:");
usernameField = new TextField();
usernameField.setPrefWidth(200);
Label passwordLabel = new Label("密码:");
final Label passwordLabel = new Label("密码:");
passwordField = new PasswordField();
passwordField.setPrefWidth(200);
loginForm.add(usernameLabel, 0, 0);
loginForm.add(usernameField, 1, 0);
loginForm.add(passwordLabel, 0, 1);
loginForm.add(passwordField, 1, 1);
// 按钮
HBox buttonBox = new HBox(10);
buttonBox.setAlignment(Pos.CENTER);
loginButton = new Button("登录");
registerButton = new Button("注册");
// 设置按钮样式
loginButton.setPrefWidth(100);
registerButton.setPrefWidth(100);
buttonBox.getChildren().addAll(loginButton, registerButton);
// 将组件添加到主布局
mainLayout.getChildren().addAll(titleLabel, loginForm, buttonBox);
// 将主布局放到边界面板中央
setCenter(mainLayout);
// 添加事件处理器
addEventHandlers();
}
/**
*
* .
*/
private void addEventHandlers() {
loginButton.setOnAction(e -> handleLogin());
registerButton.setOnAction(e -> handleRegistration());
// 允许使用回车键登录
setOnKeyPressed(event -> {
if (event.getCode().toString().equals("ENTER")) {
@ -106,7 +112,7 @@ public class LoginScene extends BorderPane {
}
/**
*
* .
*/
private void handleLogin() {
String username = usernameField.getText().trim();
@ -131,7 +137,7 @@ public class LoginScene extends BorderPane {
}
/**
*
* .
*/
private void handleRegistration() {
// 切换到注册界面
@ -140,11 +146,11 @@ public class LoginScene extends BorderPane {
}
/**
*
* .
*
* @param alertType
* @param title
* @param message
* @param title
* @param message
*/
private void showAlert(Alert.AlertType alertType, String title, String message) {
Alert alert = new Alert(alertType);

@ -1,18 +1,25 @@
package com.personalproject.ui.scenes;
import com.personalproject.controller.MathLearningController;
import com.personalproject.model.DifficultyLevel;
import com.personalproject.ui.views.MainMenuView;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.stage.Stage;
import com.personalproject.controller.MathLearningController;
import com.personalproject.model.DifficultyLevel;
import com.personalproject.ui.scenes.LoginScene;
/**
*
* .
*/
public class RegistrationScene extends BorderPane {
@ -31,120 +38,121 @@ public class RegistrationScene extends BorderPane {
private VBox registrationForm;
/**
* RegistrationScene
* RegistrationScene .
*
* @param primaryStage
* @param controller
* @param controller
*/
public RegistrationScene(Stage primaryStage, MathLearningController controller) {
this.primaryStage = primaryStage;
this.controller = controller;
initializeUI();
initializeUi();
}
/**
*
* .
*/
private void initializeUI() {
private void initializeUi() {
// 创建主布局
VBox mainLayout = new VBox(15);
mainLayout.setAlignment(Pos.CENTER);
mainLayout.setPadding(new Insets(20));
// 标题
Label titleLabel = new Label("用户注册");
final Label titleLabel = new Label("用户注册");
titleLabel.setFont(Font.font("System", FontWeight.BOLD, 24));
// 注册表单
registrationForm = new VBox(15);
registrationForm.setAlignment(Pos.CENTER);
// 步骤1填写基础信息
GridPane basicInfoForm = new GridPane();
basicInfoForm.setHgap(10);
basicInfoForm.setVgap(10);
basicInfoForm.setAlignment(Pos.CENTER);
Label usernameLabel = new Label("用户名:");
final Label usernameLabel = new Label("用户名:");
usernameField = new TextField();
usernameField.setPrefWidth(200);
Label emailLabel = new Label("邮箱:");
final Label emailLabel = new Label("邮箱:");
emailField = new TextField();
emailField.setPrefWidth(200);
Label difficultyLabel = new Label("默认难度:");
final Label difficultyLabel = new Label("默认难度:");
difficultyComboBox = new ComboBox<>();
difficultyComboBox.getItems().addAll(DifficultyLevel.PRIMARY, DifficultyLevel.MIDDLE, DifficultyLevel.HIGH);
difficultyComboBox.getItems()
.addAll(DifficultyLevel.PRIMARY, DifficultyLevel.MIDDLE, DifficultyLevel.HIGH);
difficultyComboBox.setValue(DifficultyLevel.PRIMARY);
difficultyComboBox.setPrefWidth(200);
basicInfoForm.add(usernameLabel, 0, 0);
basicInfoForm.add(usernameField, 1, 0);
basicInfoForm.add(emailLabel, 0, 1);
basicInfoForm.add(emailField, 1, 1);
basicInfoForm.add(difficultyLabel, 0, 2);
basicInfoForm.add(difficultyComboBox, 1, 2);
sendCodeButton = new Button("发送注册码");
sendCodeButton.setPrefWidth(120);
registrationForm.getChildren().addAll(basicInfoForm, sendCodeButton);
// 步骤2验证码验证初始隐藏
VBox verificationSection = new VBox(10);
verificationSection.setAlignment(Pos.CENTER);
verificationSection.setVisible(false);
verificationSection.setManaged(false);
Label codeLabel = new Label("注册码:");
final Label codeLabel = new Label("注册码:");
registrationCodeField = new TextField();
registrationCodeField.setPrefWidth(200);
verifyCodeButton = new Button("验证注册码");
verifyCodeButton.setPrefWidth(120);
verificationSection.getChildren().addAll(codeLabel, registrationCodeField, verifyCodeButton);
registrationForm.getChildren().add(verificationSection);
// 步骤3设置密码初始隐藏
VBox passwordSection = new VBox(10);
passwordSection.setAlignment(Pos.CENTER);
passwordSection.setVisible(false);
passwordSection.setManaged(false);
Label passwordLabel = new Label("设置密码 (6-10位包含大小写字母和数字):");
final Label passwordLabel = new Label("设置密码 (6-10位包含大小写字母和数字):");
passwordField = new PasswordField();
passwordField.setPrefWidth(200);
Label confirmPasswordLabel = new Label("确认密码:");
final Label confirmPasswordLabel = new Label("确认密码:");
confirmPasswordField = new PasswordField();
confirmPasswordField.setPrefWidth(200);
setPasswordButton = new Button("设置密码");
setPasswordButton.setPrefWidth(120);
passwordSection.getChildren().addAll(passwordLabel, passwordField, confirmPasswordLabel,
passwordSection.getChildren().addAll(passwordLabel, passwordField, confirmPasswordLabel,
confirmPasswordField, setPasswordButton);
registrationForm.getChildren().add(passwordSection);
// 返回按钮
backButton = new Button("返回");
backButton.setPrefWidth(100);
// 将组件添加到主布局
mainLayout.getChildren().addAll(titleLabel, registrationForm, backButton);
setCenter(mainLayout);
// 添加事件处理器
addEventHandlers(sendCodeButton, verificationSection, verifyCodeButton, passwordSection);
}
/**
*
* .
*/
private void addEventHandlers(Button sendCodeButton, VBox verificationSection,
private void addEventHandlers(Button sendCodeButton, VBox verificationSection,
Button verifyCodeButton, VBox passwordSection) {
sendCodeButton.setOnAction(e -> handleSendCode(verificationSection));
verifyCodeButton.setOnAction(e -> handleVerifyCode(passwordSection));
@ -153,12 +161,12 @@ public class RegistrationScene extends BorderPane {
}
/**
*
* .
*/
private void handleSendCode(VBox verificationSection) {
String username = usernameField.getText().trim();
String email = emailField.getText().trim();
DifficultyLevel difficultyLevel = difficultyComboBox.getValue();
final String username = usernameField.getText().trim();
final String email = emailField.getText().trim();
final DifficultyLevel difficultyLevel = difficultyComboBox.getValue();
if (username.isEmpty() || email.isEmpty()) {
showAlert(Alert.AlertType.WARNING, "警告", "请输入用户名和邮箱");
@ -183,11 +191,11 @@ public class RegistrationScene extends BorderPane {
}
/**
*
* .
*/
private void handleVerifyCode(VBox passwordSection) {
String username = usernameField.getText().trim();
String registrationCode = registrationCodeField.getText().trim();
final String username = usernameField.getText().trim();
final String registrationCode = registrationCodeField.getText().trim();
if (registrationCode.isEmpty()) {
showAlert(Alert.AlertType.WARNING, "警告", "请输入注册码");
@ -206,12 +214,12 @@ public class RegistrationScene extends BorderPane {
}
/**
*
* .
*/
private void handleSetPassword() {
String username = usernameField.getText().trim();
String password = passwordField.getText();
String confirmPassword = confirmPasswordField.getText();
final String username = usernameField.getText().trim();
final String password = passwordField.getText();
final String confirmPassword = confirmPasswordField.getText();
if (password.isEmpty() || confirmPassword.isEmpty()) {
showAlert(Alert.AlertType.WARNING, "警告", "请输入并确认密码");
@ -224,7 +232,7 @@ public class RegistrationScene extends BorderPane {
}
if (!controller.isValidPassword(password)) {
showAlert(Alert.AlertType.ERROR, "密码不符合要求",
showAlert(Alert.AlertType.ERROR, "密码不符合要求",
"密码长度必须为6-10位且包含大小写字母和数字");
return;
}
@ -232,15 +240,26 @@ public class RegistrationScene extends BorderPane {
boolean success = controller.setPassword(username, password);
if (success) {
showAlert(Alert.AlertType.INFORMATION, "注册成功", "注册成功!请登录。");
handleBack(); // 返回登录界面
var userAccountOptional = controller.getUserAccount(username);
if (userAccountOptional.isPresent()) {
showAlert(Alert.AlertType.INFORMATION, "注册成功", "注册成功!正在进入难度选择界面。");
MainMenuView mainMenuView = new MainMenuView(primaryStage, controller,
userAccountOptional.get());
if (primaryStage.getScene() != null) {
primaryStage.getScene().setRoot(mainMenuView);
}
} else {
showAlert(Alert.AlertType.WARNING, "注册提示",
"注册成功,但未能加载用户信息,请使用新密码登录。");
handleBack();
}
} else {
showAlert(Alert.AlertType.ERROR, "设置密码失败", "设置密码失败,请重试。");
}
}
/**
*
* .
*/
private void handleBack() {
LoginScene loginScene = new LoginScene(primaryStage, controller);
@ -248,11 +267,11 @@ public class RegistrationScene extends BorderPane {
}
/**
*
* .
*
* @param alertType
* @param title
* @param message
* @param title
* @param message
*/
private void showAlert(Alert.AlertType alertType, String title, String message) {
Alert alert = new Alert(alertType);

@ -1,19 +1,21 @@
package com.personalproject.ui.views;
import com.personalproject.controller.MathLearningController;
import com.personalproject.model.ExamSession;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.stage.Stage;
import com.personalproject.controller.MathLearningController;
import com.personalproject.model.ExamSession;
import com.personalproject.auth.UserAccount;
import com.personalproject.ui.views.MainMenuView;
/**
*
* .
*/
public class ExamResultsView extends BorderPane {
@ -24,72 +26,74 @@ public class ExamResultsView extends BorderPane {
private Button exitButton;
/**
* ExamResultsView
* ExamResultsView .
*
* @param primaryStage
* @param controller
* @param examSession
* @param controller
* @param examSession
*/
public ExamResultsView(Stage primaryStage, MathLearningController controller, ExamSession examSession) {
public ExamResultsView(Stage primaryStage, MathLearningController controller,
ExamSession examSession) {
this.primaryStage = primaryStage;
this.controller = controller;
this.examSession = examSession;
initializeUI();
initializeUi();
}
/**
*
* .
*/
private void initializeUI() {
private void initializeUi() {
// 创建主布局
VBox mainLayout = new VBox(20);
mainLayout.setAlignment(Pos.CENTER);
mainLayout.setPadding(new Insets(20));
// 结果标题
Label titleLabel = new Label("考试结果");
titleLabel.setFont(Font.font("System", FontWeight.BOLD, 24));
// 分数展示
double score = examSession.calculateScore();
Label scoreLabel = new Label(String.format("您的得分: %.2f%%", score));
Label scoreLabel = new Label(String.format("您的得分: %.2f", score));
scoreLabel.setFont(Font.font("System", FontWeight.BOLD, 18));
// 成绩明细
VBox breakdownBox = new VBox(10);
breakdownBox.setAlignment(Pos.CENTER);
Label totalQuestionsLabel = new Label("总题数: " + examSession.getTotalQuestions());
Label correctAnswersLabel = new Label("答对题数: " + examSession.getCorrectAnswersCount());
Label incorrectAnswersLabel = new Label("答错题数: " + examSession.getIncorrectAnswersCount());
breakdownBox.getChildren().addAll(totalQuestionsLabel, correctAnswersLabel, incorrectAnswersLabel);
breakdownBox.getChildren()
.addAll(totalQuestionsLabel, correctAnswersLabel, incorrectAnswersLabel);
// 按钮区域
HBox buttonBox = new HBox(15);
buttonBox.setAlignment(Pos.CENTER);
continueButton = new Button("继续考试");
exitButton = new Button("退出");
// 设置按钮尺寸
continueButton.setPrefSize(120, 40);
exitButton.setPrefSize(120, 40);
buttonBox.getChildren().addAll(continueButton, exitButton);
// 将组件添加到主布局
mainLayout.getChildren().addAll(titleLabel, scoreLabel, breakdownBox, buttonBox);
// 将主布局置于边界面板中央
setCenter(mainLayout);
// 添加事件处理器
addEventHandlers();
}
/**
*
* .
*/
private void addEventHandlers() {
continueButton.setOnAction(e -> handleContinue());
@ -97,7 +101,7 @@ public class ExamResultsView extends BorderPane {
}
/**
*
* .
*/
private void handleContinue() {
// 返回主菜单以开始新考试
@ -111,7 +115,7 @@ public class ExamResultsView extends BorderPane {
// 如果找不到用户信息,则提示错误并返回登录界面
showAlert(Alert.AlertType.ERROR, "错误", "用户信息无法找到,请重新登录");
// 返回登录场景
com.personalproject.ui.scenes.LoginScene loginScene =
com.personalproject.ui.scenes.LoginScene loginScene =
new com.personalproject.ui.scenes.LoginScene(primaryStage, controller);
primaryStage.getScene().setRoot(loginScene);
}
@ -119,7 +123,7 @@ public class ExamResultsView extends BorderPane {
}
/**
* 退
* 退.
*/
private void handleExit() {
// 返回主菜单
@ -133,7 +137,7 @@ public class ExamResultsView extends BorderPane {
// 如果找不到用户信息,则提示错误并返回登录界面
showAlert(Alert.AlertType.ERROR, "错误", "用户信息无法找到,请重新登录");
// 返回登录场景
com.personalproject.ui.scenes.LoginScene loginScene =
com.personalproject.ui.scenes.LoginScene loginScene =
new com.personalproject.ui.scenes.LoginScene(primaryStage, controller);
primaryStage.getScene().setRoot(loginScene);
}
@ -141,11 +145,11 @@ public class ExamResultsView extends BorderPane {
}
/**
*
* .
*
* @param alertType
* @param title
* @param message
* @param title
* @param message
*/
private void showAlert(Alert.AlertType alertType, String title, String message) {
Alert alert = new Alert(alertType);

@ -1,18 +1,25 @@
package com.personalproject.ui.views;
import com.personalproject.auth.UserAccount;
import com.personalproject.controller.MathLearningController;
import com.personalproject.model.DifficultyLevel;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.Spinner;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.stage.Stage;
import com.personalproject.controller.MathLearningController;
import com.personalproject.model.DifficultyLevel;
import com.personalproject.auth.UserAccount;
/**
*
* .
*/
public class ExamSelectionView extends BorderPane {
@ -25,78 +32,80 @@ public class ExamSelectionView extends BorderPane {
private Button backButton;
/**
* ExamSelectionView
* ExamSelectionView .
*
* @param primaryStage
* @param controller
* @param userAccount
* @param controller
* @param userAccount
*/
public ExamSelectionView(Stage primaryStage, MathLearningController controller, UserAccount userAccount) {
public ExamSelectionView(Stage primaryStage, MathLearningController controller,
UserAccount userAccount) {
this.primaryStage = primaryStage;
this.controller = controller;
this.userAccount = userAccount;
initializeUI();
initializeUi();
}
/**
*
* .
*/
private void initializeUI() {
private void initializeUi() {
// 创建主布局
VBox mainLayout = new VBox(20);
mainLayout.setAlignment(Pos.CENTER);
mainLayout.setPadding(new Insets(20));
// 标题
Label titleLabel = new Label("考试设置");
final Label titleLabel = new Label("考试设置");
titleLabel.setFont(Font.font("System", FontWeight.BOLD, 24));
// 考试设置表单
GridPane examSettingsForm = new GridPane();
examSettingsForm.setHgap(15);
examSettingsForm.setVgap(15);
examSettingsForm.setAlignment(Pos.CENTER);
Label difficultyLabel = new Label("选择难度:");
final Label difficultyLabel = new Label("选择难度:");
difficultyComboBox = new ComboBox<>();
difficultyComboBox.getItems().addAll(DifficultyLevel.PRIMARY, DifficultyLevel.MIDDLE, DifficultyLevel.HIGH);
difficultyComboBox.getItems()
.addAll(DifficultyLevel.PRIMARY, DifficultyLevel.MIDDLE, DifficultyLevel.HIGH);
difficultyComboBox.setValue(userAccount.difficultyLevel()); // 默认选中用户的难度
difficultyComboBox.setPrefWidth(200);
Label questionCountLabel = new Label("题目数量 (10-30):");
final Label questionCountLabel = new Label("题目数量 (10-30):");
questionCountSpinner = new Spinner<>(10, 30, 10); // 最小值、最大值、初始值
questionCountSpinner.setPrefWidth(200);
examSettingsForm.add(difficultyLabel, 0, 0);
examSettingsForm.add(difficultyComboBox, 1, 0);
examSettingsForm.add(questionCountLabel, 0, 1);
examSettingsForm.add(questionCountSpinner, 1, 1);
// 按钮区域
HBox buttonBox = new HBox(15);
buttonBox.setAlignment(Pos.CENTER);
startExamButton = new Button("开始考试");
backButton = new Button("返回");
// 设置按钮尺寸
startExamButton.setPrefSize(120, 40);
backButton.setPrefSize(120, 40);
buttonBox.getChildren().addAll(startExamButton, backButton);
// 将组件添加到主布局
mainLayout.getChildren().addAll(titleLabel, examSettingsForm, buttonBox);
// 将主布局置于边界面板中央
setCenter(mainLayout);
// 添加事件处理器
addEventHandlers();
}
/**
*
* .
*/
private void addEventHandlers() {
startExamButton.setOnAction(e -> handleStartExam());
@ -104,27 +113,27 @@ public class ExamSelectionView extends BorderPane {
}
/**
*
* .
*/
private void handleStartExam() {
DifficultyLevel selectedDifficulty = difficultyComboBox.getValue();
int questionCount = questionCountSpinner.getValue();
if (questionCount < 10 || questionCount > 30) {
showAlert(Alert.AlertType.WARNING, "无效输入", "题目数量必须在10到30之间");
return;
}
// 创建并启动考试会话
com.personalproject.model.ExamSession examSession = controller.createExamSession(
userAccount.username(), selectedDifficulty, questionCount);
ExamView examView = new ExamView(primaryStage, controller, examSession);
primaryStage.getScene().setRoot(examView);
}
/**
*
* .
*/
private void handleBack() {
MainMenuView mainMenuView = new MainMenuView(primaryStage, controller, userAccount);
@ -132,11 +141,11 @@ public class ExamSelectionView extends BorderPane {
}
/**
*
* .
*
* @param alertType
* @param title
* @param message
* @param title
* @param message
*/
private void showAlert(Alert.AlertType alertType, String title, String message) {
Alert alert = new Alert(alertType);

@ -1,19 +1,24 @@
package com.personalproject.ui.views;
import com.personalproject.controller.MathLearningController;
import com.personalproject.model.ExamSession;
import com.personalproject.model.QuizQuestion;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.RadioButton;
import javafx.scene.control.ToggleGroup;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.stage.Stage;
import com.personalproject.controller.MathLearningController;
import com.personalproject.model.ExamSession;
import com.personalproject.model.QuizQuestion;
import com.personalproject.ui.views.ExamResultsView;
/**
*
* .
*/
public class ExamView extends BorderPane {
@ -30,73 +35,73 @@ public class ExamView extends BorderPane {
private HBox buttonBox;
/**
* ExamView
* ExamView .
*
* @param primaryStage
* @param controller
* @param examSession
* @param controller
* @param examSession
*/
public ExamView(Stage primaryStage, MathLearningController controller, ExamSession examSession) {
this.primaryStage = primaryStage;
this.controller = controller;
this.examSession = examSession;
initializeUI();
initializeUi();
}
/**
*
* .
*/
private void initializeUI() {
private void initializeUi() {
// 创建主布局
VBox mainLayout = new VBox(20);
mainLayout.setAlignment(Pos.CENTER);
mainLayout.setPadding(new Insets(20));
// 题号
questionNumberLabel = new Label();
questionNumberLabel.setFont(Font.font("System", FontWeight.BOLD, 16));
// 题目文本
questionTextLabel = new Label();
questionTextLabel.setWrapText(true);
questionTextLabel.setFont(Font.font("System", FontWeight.NORMAL, 14));
questionTextLabel.setMaxWidth(500);
// 选项容器
optionsBox = new VBox(10);
optionsBox.setPadding(new Insets(10));
answerToggleGroup = new ToggleGroup();
// 按钮区域
buttonBox = new HBox(15);
buttonBox.setAlignment(Pos.CENTER);
previousButton = new Button("上一题");
nextButton = new Button("下一题");
finishButton = new Button("完成考试");
// 设置按钮尺寸
previousButton.setPrefSize(100, 35);
nextButton.setPrefSize(100, 35);
finishButton.setPrefSize(120, 35);
buttonBox.getChildren().addAll(previousButton, nextButton, finishButton);
// 将组件添加到主布局
mainLayout.getChildren().addAll(questionNumberLabel, questionTextLabel, optionsBox, buttonBox);
// 将主布局置于边界面板中央
setCenter(mainLayout);
// 加载第一题
loadCurrentQuestion();
// 添加事件处理器
addEventHandlers();
}
/**
*
* .
*/
private void loadCurrentQuestion() {
try {
@ -106,24 +111,24 @@ public class ExamView extends BorderPane {
updateButtonStates();
return;
}
QuizQuestion currentQuestion = examSession.getCurrentQuestion();
int currentIndex = examSession.getCurrentQuestionIndex();
if (currentQuestion == null) {
showAlert(Alert.AlertType.ERROR, "错误", "当前题目为空,请重新开始考试");
return;
}
// 更新题号与题目文本
questionNumberLabel.setText("第 " + (currentIndex + 1) + " 题");
questionTextLabel.setText(currentQuestion.getQuestionText());
// 清空上一题的选项
answerToggleGroup.selectToggle(null);
answerToggleGroup.getToggles().clear();
optionsBox.getChildren().clear();
// 创建新的选项组件
for (int i = 0; i < currentQuestion.getOptions().size(); i++) {
String option = currentQuestion.getOptions().get(i);
@ -132,14 +137,14 @@ public class ExamView extends BorderPane {
optionButton.setUserData(i); // 存储选项索引
// 如果该题已有答案则自动选中
if (examSession.hasAnswered(currentIndex) &&
examSession.getUserAnswer(currentIndex) == i) {
if (examSession.hasAnswered(currentIndex)
&& examSession.getUserAnswer(currentIndex) == i) {
optionButton.setSelected(true);
}
optionsBox.getChildren().add(optionButton);
}
// 更新按钮状态
updateButtonStates();
} catch (Exception e) {
@ -148,13 +153,13 @@ public class ExamView extends BorderPane {
}
/**
*
* .
*/
private void updateButtonStates() {
try {
int currentIndex = examSession.getCurrentQuestionIndex();
int totalQuestions = examSession.getTotalQuestions();
// 处理潜在极端情况
if (totalQuestions <= 0) {
// 如果没有题目,则禁用所有导航按钮
@ -163,13 +168,13 @@ public class ExamView extends BorderPane {
finishButton.setDisable(false); // 仍允许完成考试
return;
}
// “上一题”按钮状态
previousButton.setDisable(currentIndex < 0 || currentIndex == 0);
// “下一题”按钮状态
nextButton.setDisable(currentIndex < 0 || currentIndex >= totalQuestions - 1);
// “完成考试”按钮状态——在考试完成或到达最后一题时启用
boolean isExamComplete = examSession.isComplete();
boolean isAtLastQuestion = (currentIndex >= totalQuestions - 1);
@ -184,13 +189,13 @@ public class ExamView extends BorderPane {
}
/**
*
* .
*/
private void addEventHandlers() {
nextButton.setOnAction(e -> handleNextQuestion());
previousButton.setOnAction(e -> handlePreviousQuestion());
finishButton.setOnAction(e -> handleFinishExam());
// 添加变更监听器,在选项被选择时保存答案
answerToggleGroup.selectedToggleProperty().addListener((obs, oldSelection, newSelection) -> {
if (newSelection != null) {
@ -201,7 +206,7 @@ public class ExamView extends BorderPane {
}
/**
*
* .
*/
private void handleNextQuestion() {
try {
@ -218,7 +223,7 @@ public class ExamView extends BorderPane {
}
/**
*
* .
*/
private void handlePreviousQuestion() {
try {
@ -234,11 +239,11 @@ public class ExamView extends BorderPane {
}
/**
*
* .
*
* @param alertType
* @param title
* @param message
* @param title
* @param message
*/
private void showAlert(Alert.AlertType alertType, String title, String message) {
Alert alert = new Alert(alertType);
@ -249,12 +254,12 @@ public class ExamView extends BorderPane {
}
/**
*
* .
*/
private void handleFinishExam() {
// 保存考试结果
controller.saveExamResults(examSession);
// 展示考试结果
ExamResultsView resultsView = new ExamResultsView(primaryStage, controller, examSession);
primaryStage.getScene().setRoot(resultsView);

@ -1,113 +1,165 @@
package com.personalproject.ui.views;
import com.personalproject.auth.UserAccount;
import com.personalproject.controller.MathLearningController;
import com.personalproject.model.DifficultyLevel;
import com.personalproject.ui.scenes.LoginScene;
import java.util.Optional;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextInputDialog;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.stage.Stage;
import com.personalproject.controller.MathLearningController;
import com.personalproject.model.DifficultyLevel;
import com.personalproject.model.ExamSession;
import com.personalproject.auth.UserAccount;
import com.personalproject.ui.scenes.LoginScene;
/**
*
* .
*/
public class MainMenuView extends BorderPane {
private final Stage primaryStage;
private final MathLearningController controller;
private final UserAccount userAccount;
private Button startExamButton;
private Button changePasswordButton;
private Button logoutButton;
/**
* MainMenuView
* MainMenuView .
*
* @param primaryStage
* @param controller
* @param userAccount
* @param controller
* @param userAccount
*/
public MainMenuView(Stage primaryStage, MathLearningController controller, UserAccount userAccount) {
public MainMenuView(Stage primaryStage, MathLearningController controller,
UserAccount userAccount) {
this.primaryStage = primaryStage;
this.controller = controller;
this.userAccount = userAccount;
initializeUI();
initializeUi();
}
/**
*
* .
*/
private void initializeUI() {
private void initializeUi() {
// 创建主布局
VBox mainLayout = new VBox(20);
mainLayout.setAlignment(Pos.CENTER);
mainLayout.setPadding(new Insets(20));
// 欢迎信息
Label welcomeLabel = new Label("欢迎, " + userAccount.username());
welcomeLabel.setFont(Font.font("System", FontWeight.BOLD, 18));
// 难度信息
Label difficultyLabel = new Label("当前难度: " + userAccount.difficultyLevel().getDisplayName());
Label difficultyLabel = new Label(
"当前难度: " + userAccount.difficultyLevel().getDisplayName());
difficultyLabel.setFont(Font.font("System", FontWeight.NORMAL, 14));
Label promptLabel = new Label("请选择考试难度开始答题");
promptLabel.setFont(Font.font("System", FontWeight.NORMAL, 14));
VBox difficultyBox = new VBox(10);
difficultyBox.setAlignment(Pos.CENTER);
difficultyBox.getChildren().addAll(
createDifficultyButton(DifficultyLevel.PRIMARY),
createDifficultyButton(DifficultyLevel.MIDDLE),
createDifficultyButton(DifficultyLevel.HIGH));
// 按钮区域
VBox buttonBox = new VBox(15);
buttonBox.setAlignment(Pos.CENTER);
startExamButton = new Button("开始考试");
changePasswordButton = new Button("修改密码");
logoutButton = new Button("退出登录");
// 设置按钮尺寸
startExamButton.setPrefSize(150, 40);
changePasswordButton.setPrefSize(150, 40);
logoutButton.setPrefSize(150, 40);
buttonBox.getChildren().addAll(startExamButton, changePasswordButton, logoutButton);
buttonBox.getChildren().addAll(changePasswordButton, logoutButton);
// 将组件添加到主布局
mainLayout.getChildren().addAll(welcomeLabel, difficultyLabel, buttonBox);
mainLayout.getChildren().addAll(welcomeLabel, difficultyLabel, promptLabel, difficultyBox,
buttonBox);
// 将主布局置于边界面板中央
setCenter(mainLayout);
// 添加事件处理器
addEventHandlers();
}
/**
*
* .
*/
private void addEventHandlers() {
startExamButton.setOnAction(e -> handleStartExam());
changePasswordButton.setOnAction(e -> handleChangePassword());
logoutButton.setOnAction(e -> handleLogout());
}
/**
*
*/
private void handleStartExam() {
ExamSelectionView examSelectionView = new ExamSelectionView(primaryStage, controller, userAccount);
primaryStage.getScene().setRoot(examSelectionView);
private Button createDifficultyButton(DifficultyLevel level) {
Button button = new Button(level.getDisplayName());
button.setPrefSize(150, 40);
button.setOnAction(e -> handleDifficultySelection(level));
return button;
}
private void handleDifficultySelection(DifficultyLevel level) {
TextInputDialog dialog = new TextInputDialog("10");
dialog.setTitle("题目数量");
dialog.setHeaderText("请选择题目数量");
dialog.setContentText("请输入题目数量 (10-30):");
Optional<String> result = dialog.showAndWait();
if (result.isEmpty()) {
return;
}
int questionCount;
try {
questionCount = Integer.parseInt(result.get().trim());
} catch (NumberFormatException ex) {
showAlert(Alert.AlertType.ERROR, "无效输入", "请输入有效的数字。");
return;
}
if (questionCount < 10 || questionCount > 30) {
showAlert(Alert.AlertType.WARNING, "题目数量范围错误", "题目数量必须在10到30之间。");
return;
}
com.personalproject.model.ExamSession examSession = controller.createExamSession(
userAccount.username(), level, questionCount);
ExamView examView = new ExamView(primaryStage, controller, examSession);
primaryStage.getScene().setRoot(examView);
}
/**
*
* .
*/
private void handleChangePassword() {
PasswordChangeView passwordChangeView = new PasswordChangeView(primaryStage, controller, userAccount);
PasswordChangeView passwordChangeView = new PasswordChangeView(primaryStage, controller,
userAccount);
primaryStage.getScene().setRoot(passwordChangeView);
}
private void showAlert(Alert.AlertType alertType, String title, String message) {
Alert alert = new Alert(alertType);
alert.setTitle(title);
alert.setHeaderText(null);
alert.setContentText(message);
alert.showAndWait();
}
/**
* 退
* 退.
*/
private void handleLogout() {
// 返回登录界面

@ -1,18 +1,23 @@
package com.personalproject.ui.views;
import com.personalproject.auth.UserAccount;
import com.personalproject.controller.MathLearningController;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.PasswordField;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.stage.Stage;
import com.personalproject.controller.MathLearningController;
import com.personalproject.auth.UserAccount;
import com.personalproject.ui.views.MainMenuView;
/**
*
* .
*/
public class PasswordChangeView extends BorderPane {
@ -26,82 +31,83 @@ public class PasswordChangeView extends BorderPane {
private Button backButton;
/**
* PasswordChangeView
* PasswordChangeView .
*
* @param primaryStage
* @param controller
* @param userAccount
* @param controller
* @param userAccount
*/
public PasswordChangeView(Stage primaryStage, MathLearningController controller, UserAccount userAccount) {
public PasswordChangeView(Stage primaryStage, MathLearningController controller,
UserAccount userAccount) {
this.primaryStage = primaryStage;
this.controller = controller;
this.userAccount = userAccount;
initializeUI();
initializeUi();
}
/**
*
* .
*/
private void initializeUI() {
private void initializeUi() {
// 创建主布局
VBox mainLayout = new VBox(20);
mainLayout.setAlignment(Pos.CENTER);
mainLayout.setPadding(new Insets(20));
// 标题
Label titleLabel = new Label("修改密码");
final Label titleLabel = new Label("修改密码");
titleLabel.setFont(Font.font("System", FontWeight.BOLD, 24));
// 修改密码表单
GridPane passwordForm = new GridPane();
passwordForm.setHgap(15);
passwordForm.setVgap(15);
passwordForm.setAlignment(Pos.CENTER);
Label oldPasswordLabel = new Label("当前密码:");
final Label oldPasswordLabel = new Label("当前密码:");
oldPasswordField = new PasswordField();
oldPasswordField.setPrefWidth(200);
Label newPasswordLabel = new Label("新密码 (6-10位包含大小写字母和数字):");
final Label newPasswordLabel = new Label("新密码 (6-10位包含大小写字母和数字):");
newPasswordField = new PasswordField();
newPasswordField.setPrefWidth(200);
Label confirmNewPasswordLabel = new Label("确认新密码:");
final Label confirmNewPasswordLabel = new Label("确认新密码:");
confirmNewPasswordField = new PasswordField();
confirmNewPasswordField.setPrefWidth(200);
passwordForm.add(oldPasswordLabel, 0, 0);
passwordForm.add(oldPasswordField, 1, 0);
passwordForm.add(newPasswordLabel, 0, 1);
passwordForm.add(newPasswordField, 1, 1);
passwordForm.add(confirmNewPasswordLabel, 0, 2);
passwordForm.add(confirmNewPasswordField, 1, 2);
// 按钮区域
HBox buttonBox = new HBox(15);
buttonBox.setAlignment(Pos.CENTER);
changePasswordButton = new Button("修改密码");
backButton = new Button("返回");
// 设置按钮尺寸
changePasswordButton.setPrefSize(120, 40);
backButton.setPrefSize(120, 40);
buttonBox.getChildren().addAll(changePasswordButton, backButton);
// 将组件添加到主布局
mainLayout.getChildren().addAll(titleLabel, passwordForm, buttonBox);
// 将主布局置于边界面板中央
setCenter(mainLayout);
// 添加事件处理器
addEventHandlers();
}
/**
*
* .
*/
private void addEventHandlers() {
changePasswordButton.setOnAction(e -> handleChangePassword());
@ -109,7 +115,7 @@ public class PasswordChangeView extends BorderPane {
}
/**
*
* .
*/
private void handleChangePassword() {
String oldPassword = oldPasswordField.getText();
@ -127,7 +133,7 @@ public class PasswordChangeView extends BorderPane {
}
if (!controller.isValidPassword(newPassword)) {
showAlert(Alert.AlertType.ERROR, "密码不符合要求",
showAlert(Alert.AlertType.ERROR, "密码不符合要求",
"密码长度必须为6-10位且包含大小写字母和数字");
return;
}
@ -143,7 +149,7 @@ public class PasswordChangeView extends BorderPane {
}
/**
*
* .
*/
private void handleBack() {
MainMenuView mainMenuView = new MainMenuView(primaryStage, controller, userAccount);
@ -151,11 +157,11 @@ public class PasswordChangeView extends BorderPane {
}
/**
*
* .
*
* @param alertType
* @param title
* @param message
* @param title
* @param message
*/
private void showAlert(Alert.AlertType alertType, String title, String message) {
Alert alert = new Alert(alertType);

@ -17,4 +17,4 @@ mail.username=soloyouth@126.com
mail.password=ZYsjxwDXFBsWeQcX
mail.from=soloyouth@126.com
mail.subject=数学学习软件注册验证码
mail.debug=true
mail.debug=true

Loading…
Cancel
Save