You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
118 lines
3.4 KiB
118 lines
3.4 KiB
package com.mathapp;
|
|
|
|
import com.formdev.flatlaf.FlatLightLaf;
|
|
import com.mathapp.models.TestPaper;
|
|
import com.mathapp.panels.*;
|
|
|
|
import javax.swing.*;
|
|
import java.awt.*;
|
|
|
|
/**
|
|
* 应用程序主类
|
|
* 负责初始化UI、管理面板切换和维护全局状态。
|
|
*/
|
|
public class MathApp extends JFrame {
|
|
|
|
private CardLayout cardLayout;
|
|
private JPanel mainPanel;
|
|
private String currentUserEmail;
|
|
|
|
public static final String LOGIN_PANEL = "LoginPanel";
|
|
public static final String REGISTER_PANEL = "RegisterPanel";
|
|
public static final String SET_PASSWORD_PANEL = "SetPasswordPanel";
|
|
public static final String MAIN_MENU_PANEL = "MainMenuPanel";
|
|
public static final String QUIZ_PANEL = "QuizPanel";
|
|
public static final String RESULTS_PANEL = "ResultsPanel";
|
|
public static final String CHANGE_PASSWORD_PANEL = "ChangePasswordPanel";
|
|
|
|
public MathApp() {
|
|
initUI();
|
|
}
|
|
|
|
private void initUI() {
|
|
setTitle("数学学习平台");
|
|
setSize(800, 600);
|
|
setResizable(false);
|
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
setLocationRelativeTo(null);
|
|
|
|
cardLayout = new CardLayout();
|
|
mainPanel = new JPanel(cardLayout);
|
|
|
|
// 添加所有静态面板
|
|
mainPanel.add(new LoginPanel(this), LOGIN_PANEL);
|
|
mainPanel.add(new RegisterPanel(this), REGISTER_PANEL);
|
|
mainPanel.add(new MainMenuPanel(this), MAIN_MENU_PANEL);
|
|
mainPanel.add(new ChangePasswordPanel(this), CHANGE_PASSWORD_PANEL);
|
|
|
|
add(mainPanel);
|
|
}
|
|
|
|
/**
|
|
* 切换到指定的面板
|
|
* @param panelName 要显示的面板名称
|
|
*/
|
|
public void showPanel(String panelName) {
|
|
cardLayout.show(mainPanel, panelName);
|
|
}
|
|
|
|
/**
|
|
* 注册成功后,动态创建并跳转到设置密码面板
|
|
* @param email 刚刚注册成功的用户邮箱
|
|
*/
|
|
public void showSetPasswordPanel(String email) {
|
|
this.currentUserEmail = email; // 临时存储
|
|
SetPasswordPanel setPasswordPanel = new SetPasswordPanel(this, email);
|
|
mainPanel.add(setPasswordPanel, SET_PASSWORD_PANEL);
|
|
showPanel(SET_PASSWORD_PANEL);
|
|
}
|
|
|
|
/**
|
|
* 开始一场新的测验
|
|
* @param level "小学", "初中", 或 "高中"
|
|
* @param questionCount 题目数量
|
|
*/
|
|
public void startQuiz(String level, int questionCount) {
|
|
QuizPanel quizPanel = new QuizPanel(this, level, questionCount);
|
|
mainPanel.add(quizPanel, QUIZ_PANEL);
|
|
showPanel(QUIZ_PANEL);
|
|
}
|
|
|
|
/**
|
|
* 显示测验结果
|
|
* @param score 用户得分
|
|
* @param totalQuestions 题目总数
|
|
* @param testPaper 完整的试卷数据,用于保存
|
|
*/
|
|
public void showResults(int score, int totalQuestions, TestPaper testPaper) {
|
|
ResultsPanel resultsPanel = new ResultsPanel(this, score, totalQuestions);
|
|
mainPanel.add(resultsPanel, RESULTS_PANEL);
|
|
showPanel(RESULTS_PANEL);
|
|
}
|
|
|
|
public void setCurrentUserEmail(String email) {
|
|
this.currentUserEmail = email;
|
|
}
|
|
|
|
public String getCurrentUserEmail() {
|
|
return currentUserEmail;
|
|
}
|
|
|
|
|
|
public static void main(String[] args) {
|
|
// 设置现代化UI外观
|
|
FlatLightLaf.setup();
|
|
// 全局UI定制
|
|
UIManager.put("Button.arc", 15);
|
|
UIManager.put("Component.arc", 15);
|
|
UIManager.put("ProgressBar.arc", 999);
|
|
UIManager.put("TextComponent.arc", 15);
|
|
UIManager.put("OptionPane.buttonAreaBorder", BorderFactory.createEmptyBorder(10, 0, 0, 0));
|
|
|
|
|
|
EventQueue.invokeLater(() -> {
|
|
MathApp ex = new MathApp();
|
|
ex.setVisible(true);
|
|
});
|
|
}
|
|
} |