v2.2 后端代码checkstyle检查完毕

pull/13/head
杨博文 4 months ago
parent 773d83be67
commit bc0e65dbeb

@ -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;
}

@ -20,8 +20,8 @@ import java.util.Stack;
*
* <p>:
* <ul>
* <li>{@code "3 + 开根号 16 平方"} {@code "3 + (sqrt(16))^2"} = {@code "3 + 4^2"} = {@code "3 + 16"} = 19</li>
* <li>{@code "开根号 ( 4 + 5 ) 平方"} {@code "(sqrt(4+5))^2"} = {@code "sqrt(9)^2"} = {@code "3^2"} = 9</li>
* <li>{@code "3 + 开根号 16 平方"} {@code "3 + (sqrt(16))^2"} = 19</li>
* <li>{@code "开根号 ( 4 + 5 ) 平方"} {@code "(sqrt(4+5))^2"} = 9</li>
* <li>{@code "sin 30 + 5"} {@code "sin(30) + 5"} (30)</li>
* </ul>
*
@ -134,9 +134,9 @@ public class AdvancedCaculate {
private static void handleBasicOperator(String token, Stack<Double> numberStack,
Stack<String> 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);

@ -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<String> 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)) {

@ -111,38 +111,38 @@ public class EmailService {
* @return HTML
*/
private static String createEmailContent(String code) {
return "<!DOCTYPE html>" +
"<html>" +
"<head>" +
"<meta charset='UTF-8'>" +
"<style>" +
"body { font-family: Arial, sans-serif; line-height: 1.6; color: #333; }" +
".container { max-width: 600px; margin: 0 auto; padding: 20px; }" +
".header { background-color: #4CAF50; color: white; padding: 20px; text-align: center; }" +
".content { padding: 20px; background-color: #f9f9f9; margin: 20px 0; }" +
".code { font-size: 24px; font-weight: bold; color: #4CAF50; text-align: center; padding: 15px; background-color: white; border: 2px dashed #4CAF50; margin: 20px 0; }"
+
".footer { text-align: center; color: #666; font-size: 12px; }" +
"</style>" +
"</head>" +
"<body>" +
"<div class='container'>" +
"<div class='header'>" +
"<h2>用户注册验证码</h2>" +
"</div>" +
"<div class='content'>" +
"<p>您好!</p>" +
"<p>您正在注册账户,验证码如下:</p>" +
"<div class='code'>" + code + "</div>" +
"<p>验证码有效期为 " + EmailConfig.CODE_EXPIRY_MINUTES + " 分钟,请勿泄露给他人。</p>" +
"<p>如果这不是您本人的操作,请忽略此邮件。</p>" +
"</div>" +
"<div class='footer'>" +
"<p>此邮件为系统自动发送,请勿回复。</p>" +
"</div>" +
"</div>" +
"</body>" +
"</html>";
return "<!DOCTYPE html>"
+ "<html>"
+ "<head>"
+ "<meta charset='UTF-8'>"
+ "<style>"
+ "body { font-family: Arial, sans-serif; line-height: 1.6; color: #333; }"
+ ".container { max-width: 600px; margin: 0 auto; padding: 20px; }"
+ ".header { background-color: #4CAF50; color: white; padding: 20px; text-align: center; }"
+ ".content { padding: 20px; background-color: #f9f9f9; margin: 20px 0; }"
+ ".code { font-size: 24px; font-weight: bold; color: #4CAF50; text-align: center; "
+ "padding: 15px; background-color: white; border: 2px dashed #4CAF50; margin: 20px 0; }"
+ ".footer { text-align: center; color: #666; font-size: 12px; }"
+ "</style>"
+ "</head>"
+ "<body>"
+ "<div class='container'>"
+ "<div class='header'>"
+ "<h2>用户注册验证码</h2>"
+ "</div>"
+ "<div class='content'>"
+ "<p>您好!</p>"
+ "<p>您正在注册账户,验证码如下:</p>"
+ "<div class='code'>" + code + "</div>"
+ "<p>验证码有效期为 " + EmailConfig.CODE_EXPIRY_MINUTES + " 分钟,请勿泄露给他人。</p>"
+ "<p>如果这不是您本人的操作,请忽略此邮件。</p>"
+ "</div>"
+ "<div class='footer'>"
+ "<p>此邮件为系统自动发送,请勿回复。</p>"
+ "</div>"
+ "</div>"
+ "</body>"
+ "</html>";
}
/**
@ -178,8 +178,8 @@ public class EmailService {
while (iterator.hasNext()) {
Map.Entry<String, VerificationCodeInfo> 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();
}
}

Loading…
Cancel
Save