commit
6c140dd776
@ -0,0 +1,81 @@
|
||||
package ui;
|
||||
|
||||
import ui.panels.*;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class MainFrame extends JFrame {
|
||||
private CardLayout cardLayout;
|
||||
private JPanel mainPanel;
|
||||
|
||||
// 页面标识常量
|
||||
public static final String LOGIN_PAGE = "LOGIN";
|
||||
public static final String REGISTER_PAGE = "REGISTER";
|
||||
public static final String GRADE_SELECT_PAGE = "GRADE_SELECT";
|
||||
public static final String QUESTION_COUNT_PAGE = "QUESTION_COUNT";
|
||||
public static final String EXAM_PAGE = "EXAM";
|
||||
public static final String RESULT_PAGE = "RESULT";
|
||||
|
||||
// 保存面板引用
|
||||
private QuestionCountPanel questionCountPanel;
|
||||
private ExamPanel examPanel;
|
||||
|
||||
public MainFrame() {
|
||||
initializeUI();
|
||||
}
|
||||
|
||||
private void initializeUI() {
|
||||
setTitle("数学学习软件");
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setSize(800, 600);
|
||||
setLocationRelativeTo(null); // 窗口居中
|
||||
|
||||
cardLayout = new CardLayout();
|
||||
mainPanel = new JPanel(cardLayout);
|
||||
|
||||
// 创建各个面板并添加到主面板
|
||||
mainPanel.add(new LoginPanel(this), LOGIN_PAGE);
|
||||
mainPanel.add(new RegisterPanel(this), REGISTER_PAGE);
|
||||
mainPanel.add(new GradeSelectPanel(this), GRADE_SELECT_PAGE);
|
||||
|
||||
// 保存题目数量面板引用
|
||||
questionCountPanel = new QuestionCountPanel(this);
|
||||
mainPanel.add(questionCountPanel, QUESTION_COUNT_PAGE);
|
||||
|
||||
// 保存考试面板引用
|
||||
examPanel = new ExamPanel(this);
|
||||
mainPanel.add(examPanel, EXAM_PAGE);
|
||||
|
||||
mainPanel.add(new ResultPanel(this), RESULT_PAGE);
|
||||
|
||||
add(mainPanel);
|
||||
|
||||
// 默认显示登录页面
|
||||
showPanel(LOGIN_PAGE);
|
||||
}
|
||||
|
||||
public void showPanel(String panelName) {
|
||||
cardLayout.show(mainPanel, panelName);
|
||||
|
||||
// 当切换到考试界面时,自动触发同步
|
||||
if (EXAM_PAGE.equals(panelName) && examPanel != null) {
|
||||
System.out.println("自动触发考试界面同步");
|
||||
examPanel.autoSyncExamState();
|
||||
}
|
||||
}
|
||||
|
||||
// 获取主框架实例,用于面板间通信
|
||||
public MainFrame getMainFrame() {
|
||||
return this;
|
||||
}
|
||||
|
||||
// 添加缺失的方法
|
||||
public QuestionCountPanel getQuestionCountPanel() {
|
||||
return questionCountPanel;
|
||||
}
|
||||
|
||||
// 获取考试面板
|
||||
public ExamPanel getExamPanel() {
|
||||
return examPanel;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,27 @@
|
||||
package ui;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class MathLearningApp {
|
||||
public static void main(String[] args) {
|
||||
// 确保界面创建在事件分发线程中
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
// 设置系统外观 - 使用正确的方法
|
||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
try {
|
||||
// 如果系统外观设置失败,使用默认的跨平台外观
|
||||
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
new MainFrame().setVisible(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,264 @@
|
||||
package ui.panels;
|
||||
|
||||
import Base.Exam_result;
|
||||
import ui.MainFrame;
|
||||
import ui.service.BackendService;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class ExamPanel extends JPanel {
|
||||
private MainFrame mainFrame;
|
||||
private JLabel questionLabel;
|
||||
private JRadioButton[] optionButtons;
|
||||
private ButtonGroup buttonGroup;
|
||||
private JLabel progressLabel;
|
||||
private JButton prevBtn;
|
||||
private JButton nextBtn;
|
||||
private JButton submitBtn;
|
||||
private JButton forceReloadBtn;
|
||||
|
||||
// 添加自动同步标志
|
||||
private boolean autoSynced = false;
|
||||
|
||||
public ExamPanel(MainFrame mainFrame) {
|
||||
this.mainFrame = mainFrame;
|
||||
initializeUI();
|
||||
}
|
||||
|
||||
private void initializeUI() {
|
||||
setLayout(new BorderLayout(10, 10));
|
||||
setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
|
||||
|
||||
// 进度显示
|
||||
progressLabel = new JLabel("等待试卷加载...", JLabel.CENTER);
|
||||
progressLabel.setFont(new Font("宋体", Font.BOLD, 16));
|
||||
|
||||
// 题目显示
|
||||
questionLabel = new JLabel("", JLabel.CENTER);
|
||||
questionLabel.setFont(new Font("宋体", Font.PLAIN, 16));
|
||||
questionLabel.setBorder(BorderFactory.createEmptyBorder(20, 10, 20, 10));
|
||||
|
||||
// 选项面板
|
||||
JPanel optionsPanel = new JPanel(new GridLayout(4, 1, 10, 10));
|
||||
optionsPanel.setBorder(BorderFactory.createTitledBorder("请选择答案"));
|
||||
optionButtons = new JRadioButton[4];
|
||||
buttonGroup = new ButtonGroup();
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
optionButtons[i] = new JRadioButton();
|
||||
optionButtons[i].setFont(new Font("宋体", Font.PLAIN, 14));
|
||||
buttonGroup.add(optionButtons[i]);
|
||||
optionsPanel.add(optionButtons[i]);
|
||||
}
|
||||
|
||||
// 按钮面板
|
||||
JPanel buttonPanel = new JPanel(new GridLayout(1, 4, 10, 10));
|
||||
prevBtn = new JButton("上一题");
|
||||
nextBtn = new JButton("下一题");
|
||||
submitBtn = new JButton("提交试卷");
|
||||
forceReloadBtn = new JButton("强制同步");
|
||||
|
||||
prevBtn.addActionListener(e -> showPreviousQuestion());
|
||||
nextBtn.addActionListener(e -> showNextQuestion());
|
||||
submitBtn.addActionListener(e -> finishExam());
|
||||
forceReloadBtn.addActionListener(e -> forceSyncExamState());
|
||||
|
||||
buttonPanel.add(prevBtn);
|
||||
buttonPanel.add(nextBtn);
|
||||
buttonPanel.add(submitBtn);
|
||||
buttonPanel.add(forceReloadBtn);
|
||||
|
||||
// 添加到主面板
|
||||
add(progressLabel, BorderLayout.NORTH);
|
||||
add(questionLabel, BorderLayout.CENTER);
|
||||
add(optionsPanel, BorderLayout.EAST);
|
||||
add(buttonPanel, BorderLayout.SOUTH);
|
||||
|
||||
// 初始状态显示等待
|
||||
showWaitingState();
|
||||
}
|
||||
|
||||
// 添加自动同步方法
|
||||
public void autoSyncExamState() {
|
||||
if (!autoSynced) {
|
||||
System.out.println("=== 自动同步试卷状态 ===");
|
||||
forceSyncExamState();
|
||||
autoSynced = true;
|
||||
}
|
||||
}
|
||||
|
||||
// 显示等待状态
|
||||
private void showWaitingState() {
|
||||
progressLabel.setText("等待同步");
|
||||
questionLabel.setText("<html><div style='text-align: center; padding: 20px;'>" +
|
||||
"等待试卷数据同步,请稍候...</div></html>");
|
||||
|
||||
String[] waitingOptions = {"A. 同步中...", "B. 同步中...", "C. 同步中...", "D. 同步中..."};
|
||||
for (int i = 0; i < 4; i++) {
|
||||
optionButtons[i].setText(waitingOptions[i]);
|
||||
optionButtons[i].setEnabled(false);
|
||||
}
|
||||
|
||||
buttonGroup.clearSelection();
|
||||
|
||||
// 禁用所有功能按钮
|
||||
prevBtn.setEnabled(false);
|
||||
nextBtn.setEnabled(false);
|
||||
submitBtn.setEnabled(false);
|
||||
forceReloadBtn.setEnabled(true);
|
||||
}
|
||||
|
||||
private void forceSyncExamState() {
|
||||
System.out.println("=== 强制同步试卷状态 ===");
|
||||
|
||||
// 重置自动同步标志
|
||||
autoSynced = true;
|
||||
|
||||
// 强制重新加载
|
||||
BackendService.reloadCurrentQuestion();
|
||||
|
||||
// 检查试卷状态
|
||||
String status = BackendService.getExamStatus();
|
||||
System.out.println("试卷状态: " + status);
|
||||
|
||||
int totalQuestions = BackendService.getTotalQuestions();
|
||||
int currentIndex = BackendService.getCurrentQuestionIndex();
|
||||
|
||||
System.out.println("题目总数: " + totalQuestions);
|
||||
System.out.println("当前索引: " + currentIndex);
|
||||
|
||||
if ("READY".equals(status) && totalQuestions > 0) {
|
||||
showCurrentQuestion();
|
||||
} else {
|
||||
showErrorState("试卷同步失败,状态: " + status +
|
||||
",题目数: " + totalQuestions +
|
||||
",当前索引: " + currentIndex);
|
||||
}
|
||||
}
|
||||
|
||||
private void showErrorState(String errorMessage) {
|
||||
progressLabel.setText("系统提示");
|
||||
questionLabel.setText("<html><div style='text-align: center; color: red; padding: 20px;'>" +
|
||||
errorMessage + "</div></html>");
|
||||
|
||||
// 设置默认选项
|
||||
String[] defaultOptions = {"A. 请点击强制同步", "B. 检查后端日志", "C. 重新生成试卷", "D. 联系技术支持"};
|
||||
for (int i = 0; i < 4; i++) {
|
||||
optionButtons[i].setText(defaultOptions[i]);
|
||||
optionButtons[i].setEnabled(false);
|
||||
}
|
||||
|
||||
buttonGroup.clearSelection();
|
||||
|
||||
// 禁用功能按钮,只保留同步按钮
|
||||
prevBtn.setEnabled(false);
|
||||
nextBtn.setEnabled(false);
|
||||
submitBtn.setEnabled(false);
|
||||
forceReloadBtn.setEnabled(true);
|
||||
}
|
||||
|
||||
private void showCurrentQuestion() {
|
||||
String questionText = BackendService.getCurrentQuestionText();
|
||||
String[] options = BackendService.getCurrentQuestionOptions();
|
||||
|
||||
int currentIndex = BackendService.getCurrentQuestionIndex();
|
||||
int totalQuestions = BackendService.getTotalQuestions();
|
||||
|
||||
// 更新显示
|
||||
progressLabel.setText(String.format("第 %d/%d 题", currentIndex + 1, totalQuestions));
|
||||
questionLabel.setText(questionText);
|
||||
|
||||
// 更新选项
|
||||
for (int i = 0; i < 4; i++) {
|
||||
optionButtons[i].setText(options[i]);
|
||||
optionButtons[i].setEnabled(true);
|
||||
}
|
||||
|
||||
// 恢复用户之前的选择
|
||||
Integer userAnswer = BackendService.getUserAnswer(currentIndex);
|
||||
if (userAnswer != null && userAnswer >= 0 && userAnswer < 4) {
|
||||
optionButtons[userAnswer].setSelected(true);
|
||||
} else {
|
||||
buttonGroup.clearSelection();
|
||||
}
|
||||
|
||||
// 更新按钮状态
|
||||
updateButtonStates();
|
||||
}
|
||||
|
||||
private void showNextQuestion() {
|
||||
int selectedAnswer = getSelectedAnswer();
|
||||
if (selectedAnswer != -1) {
|
||||
boolean hasNext = BackendService.submitAnswer(selectedAnswer);
|
||||
if (hasNext) {
|
||||
showCurrentQuestion();
|
||||
} else {
|
||||
finishExam();
|
||||
}
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(this, "请选择一个答案");
|
||||
}
|
||||
}
|
||||
|
||||
private void showPreviousQuestion() {
|
||||
if (BackendService.getPreviousQuestion()) {
|
||||
showCurrentQuestion();
|
||||
}
|
||||
}
|
||||
|
||||
private int getSelectedAnswer() {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (optionButtons[i].isSelected()) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
private void updateButtonStates() {
|
||||
int currentIndex = BackendService.getCurrentQuestionIndex();
|
||||
int totalQuestions = BackendService.getTotalQuestions();
|
||||
|
||||
boolean hasPrevious = currentIndex > 0;
|
||||
boolean hasNext = currentIndex < totalQuestions - 1;
|
||||
boolean isLastQuestion = currentIndex == totalQuestions - 1;
|
||||
|
||||
prevBtn.setEnabled(hasPrevious && totalQuestions > 0);
|
||||
nextBtn.setEnabled(hasNext && totalQuestions > 0);
|
||||
submitBtn.setEnabled(isLastQuestion && totalQuestions > 0);
|
||||
forceReloadBtn.setEnabled(true);
|
||||
}
|
||||
|
||||
private void finishExam() {
|
||||
System.out.println("=== 完成考试 ===");
|
||||
|
||||
// 提交最后一题的答案
|
||||
int selectedAnswer = getSelectedAnswer();
|
||||
if (selectedAnswer != -1) {
|
||||
System.out.println("提交最后一题答案: " + selectedAnswer);
|
||||
BackendService.submitAnswer(selectedAnswer);
|
||||
} else {
|
||||
System.out.println("最后一题未选择答案,提交默认答案");
|
||||
BackendService.submitAnswer(0);
|
||||
}
|
||||
|
||||
// 计算并缓存考试结果
|
||||
Exam_result result = BackendService.finishExam();
|
||||
if (result != null) {
|
||||
System.out.println("考试结果计算成功,准备跳转到结果页面");
|
||||
} else {
|
||||
System.out.println("考试结果计算失败");
|
||||
JOptionPane.showMessageDialog(this,
|
||||
"考试结果计算失败,请重新考试",
|
||||
"错误",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
|
||||
// 重置自动同步标志
|
||||
autoSynced = false;
|
||||
|
||||
// 显示考试结果
|
||||
mainFrame.showPanel(MainFrame.RESULT_PAGE);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,79 @@
|
||||
package ui.panels;
|
||||
|
||||
import ui.MainFrame;
|
||||
import ui.service.BackendService;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class GradeSelectPanel extends JPanel {
|
||||
private MainFrame mainFrame;
|
||||
private String selectedGrade;
|
||||
|
||||
public GradeSelectPanel(MainFrame mainFrame) {
|
||||
this.mainFrame = mainFrame;
|
||||
initializeUI();
|
||||
}
|
||||
|
||||
private void initializeUI() {
|
||||
setLayout(new GridLayout(5, 1, 10, 10));
|
||||
setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
|
||||
|
||||
JLabel titleLabel = new JLabel("选择年级", JLabel.CENTER);
|
||||
titleLabel.setFont(new Font("宋体", Font.BOLD, 18));
|
||||
|
||||
JButton primaryBtn = new JButton("小学");
|
||||
JButton middleBtn = new JButton("初中");
|
||||
JButton highBtn = new JButton("高中");
|
||||
JButton backBtn = new JButton("返回");
|
||||
|
||||
// 为每个按钮设置年级并跳转
|
||||
primaryBtn.addActionListener(e -> {
|
||||
selectedGrade = "小学";
|
||||
showQuestionCountPanel();
|
||||
});
|
||||
|
||||
middleBtn.addActionListener(e -> {
|
||||
selectedGrade = "初中";
|
||||
showQuestionCountPanel();
|
||||
});
|
||||
|
||||
highBtn.addActionListener(e -> {
|
||||
selectedGrade = "高中";
|
||||
showQuestionCountPanel();
|
||||
});
|
||||
|
||||
backBtn.addActionListener(e -> {
|
||||
mainFrame.showPanel(MainFrame.LOGIN_PAGE);
|
||||
});
|
||||
|
||||
add(titleLabel);
|
||||
add(primaryBtn);
|
||||
add(middleBtn);
|
||||
add(highBtn);
|
||||
add(backBtn);
|
||||
}
|
||||
|
||||
// 显示题目数量选择面板
|
||||
private void showQuestionCountPanel() {
|
||||
// 使用更简单的方式传递年级信息
|
||||
// 直接跳转到题目数量页面,年级信息会在进入时设置
|
||||
try {
|
||||
// 尝试通过主框架获取题目数量面板
|
||||
QuestionCountPanel questionCountPanel = mainFrame.getQuestionCountPanel();
|
||||
if (questionCountPanel != null) {
|
||||
questionCountPanel.setGrade(selectedGrade);
|
||||
mainFrame.showPanel(MainFrame.QUESTION_COUNT_PAGE);
|
||||
} else {
|
||||
// 如果获取失败,使用备用方案
|
||||
JOptionPane.showMessageDialog(this,
|
||||
"系统初始化中,请稍后重试");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// 如果出现异常,使用备用方案
|
||||
System.out.println("获取题目数量面板异常: " + e.getMessage());
|
||||
// 直接跳转,年级信息将在进入页面后设置
|
||||
mainFrame.showPanel(MainFrame.QUESTION_COUNT_PAGE);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,59 @@
|
||||
package ui.panels;
|
||||
|
||||
import ui.MainFrame;
|
||||
import ui.service.BackendService;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class LoginPanel extends JPanel {
|
||||
private MainFrame mainFrame;
|
||||
|
||||
public LoginPanel(MainFrame mainFrame) {
|
||||
this.mainFrame = mainFrame;
|
||||
initializeUI();
|
||||
}
|
||||
|
||||
private void initializeUI() {
|
||||
setLayout(new GridLayout(4, 2, 10, 10));
|
||||
setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
|
||||
|
||||
JLabel userIdLabel = new JLabel("用户名:");
|
||||
JTextField userIdField = new JTextField();
|
||||
JLabel passwordLabel = new JLabel("密码:");
|
||||
JPasswordField passwordField = new JPasswordField();
|
||||
|
||||
JButton loginBtn = new JButton("登录");
|
||||
JButton registerBtn = new JButton("注册");
|
||||
|
||||
loginBtn.addActionListener(e -> {
|
||||
String userId = userIdField.getText();
|
||||
String password = new String(passwordField.getPassword());
|
||||
|
||||
if (userId.isEmpty() || password.isEmpty()) {
|
||||
JOptionPane.showMessageDialog(this, "请输入用户名和密码");
|
||||
return;
|
||||
}
|
||||
|
||||
// 调用后端登录服务
|
||||
boolean success = BackendService.login(userId, password);
|
||||
if (success) {
|
||||
JOptionPane.showMessageDialog(this, "登录成功");
|
||||
mainFrame.showPanel(MainFrame.GRADE_SELECT_PAGE);
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(this, "登录失败,请检查用户名和密码");
|
||||
}
|
||||
});
|
||||
|
||||
registerBtn.addActionListener(e -> {
|
||||
mainFrame.showPanel(MainFrame.REGISTER_PAGE);
|
||||
});
|
||||
|
||||
add(userIdLabel);
|
||||
add(userIdField);
|
||||
add(passwordLabel);
|
||||
add(passwordField);
|
||||
add(loginBtn);
|
||||
add(registerBtn);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,123 @@
|
||||
package ui.panels;
|
||||
|
||||
import ui.MainFrame;
|
||||
import ui.service.BackendService;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class QuestionCountPanel extends JPanel {
|
||||
private MainFrame mainFrame;
|
||||
private String currentGrade;
|
||||
|
||||
public QuestionCountPanel(MainFrame mainFrame) {
|
||||
this.mainFrame = mainFrame;
|
||||
this.currentGrade = "小学";
|
||||
initializeUI();
|
||||
}
|
||||
|
||||
public void setGrade(String grade) {
|
||||
this.currentGrade = grade;
|
||||
System.out.println("设置年级: " + grade);
|
||||
}
|
||||
|
||||
private void initializeUI() {
|
||||
setLayout(new GridLayout(7, 2, 10, 10));
|
||||
setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
|
||||
|
||||
JLabel titleLabel = new JLabel("生成试卷", JLabel.CENTER);
|
||||
titleLabel.setFont(new Font("宋体", Font.BOLD, 16));
|
||||
|
||||
JLabel countLabel = new JLabel("题目数量:");
|
||||
JTextField countField = new JTextField("10");
|
||||
JLabel gradeLabel = new JLabel("当前年级:");
|
||||
JLabel currentGradeLabel = new JLabel(currentGrade);
|
||||
|
||||
JButton generateBtn = new JButton("生成试卷");
|
||||
JButton testBtn = new JButton("测试模式");
|
||||
JButton backBtn = new JButton("返回");
|
||||
|
||||
generateBtn.addActionListener(e -> {
|
||||
try {
|
||||
int count = Integer.parseInt(countField.getText());
|
||||
if (count <= 0 || count > 50) {
|
||||
JOptionPane.showMessageDialog(this, "请输入1-50之间的题目数量");
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.println("=== 生成试卷请求 ===");
|
||||
System.out.println("年级: " + currentGrade + ", 题目数量: " + count);
|
||||
|
||||
// 确保用户ID存在
|
||||
if (BackendService.getCurrentUserId() == null) {
|
||||
BackendService.setTempUserId("temp_user_" + System.currentTimeMillis());
|
||||
}
|
||||
|
||||
boolean success = BackendService.generatePaper(currentGrade, count);
|
||||
|
||||
if (success) {
|
||||
// 立即检查状态
|
||||
String status = BackendService.getExamStatus();
|
||||
int totalQuestions = BackendService.getTotalQuestions();
|
||||
int currentIndex = BackendService.getCurrentQuestionIndex();
|
||||
|
||||
System.out.println("生成后状态: " + status +
|
||||
", 题目数: " + totalQuestions +
|
||||
", 当前索引: " + currentIndex);
|
||||
|
||||
if ("READY".equals(status) && totalQuestions > 0) {
|
||||
JOptionPane.showMessageDialog(this,
|
||||
String.format("成功生成%d道%s数学题目", totalQuestions, currentGrade));
|
||||
// 重置自动同步状态
|
||||
BackendService.resetAutoSync();
|
||||
// 跳转到考试界面
|
||||
mainFrame.showPanel(MainFrame.EXAM_PAGE);
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(this,
|
||||
"试卷生成但状态异常,状态: " + status +
|
||||
",题目数: " + totalQuestions +
|
||||
",当前索引: " + currentIndex);
|
||||
}
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(this, "试卷生成失败,请检查控制台日志");
|
||||
}
|
||||
} catch (NumberFormatException ex) {
|
||||
JOptionPane.showMessageDialog(this, "请输入有效的数字");
|
||||
}
|
||||
});
|
||||
|
||||
testBtn.addActionListener(e -> {
|
||||
// 使用测试数据
|
||||
System.out.println("=== 测试模式 ===");
|
||||
|
||||
// 确保用户ID存在
|
||||
if (BackendService.getCurrentUserId() == null) {
|
||||
BackendService.setTempUserId("test_user_" + System.currentTimeMillis());
|
||||
}
|
||||
|
||||
boolean success = BackendService.generatePaper("小学", 5);
|
||||
if (success) {
|
||||
JOptionPane.showMessageDialog(this, "测试试卷生成成功");
|
||||
// 重置自动同步状态
|
||||
BackendService.resetAutoSync();
|
||||
mainFrame.showPanel(MainFrame.EXAM_PAGE);
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(this, "测试试卷生成失败");
|
||||
}
|
||||
});
|
||||
|
||||
backBtn.addActionListener(e -> {
|
||||
mainFrame.showPanel(MainFrame.GRADE_SELECT_PAGE);
|
||||
});
|
||||
|
||||
add(titleLabel);
|
||||
add(new JLabel());
|
||||
add(countLabel);
|
||||
add(countField);
|
||||
add(gradeLabel);
|
||||
add(currentGradeLabel);
|
||||
add(generateBtn);
|
||||
add(testBtn);
|
||||
add(backBtn);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue