|
|
|
|
@ -7,6 +7,8 @@ import Base.Question;
|
|
|
|
|
|
|
|
|
|
import javax.swing.*;
|
|
|
|
|
import java.awt.*;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
public class MainFrame extends JFrame {
|
|
|
|
|
private final User_service userService;
|
|
|
|
|
private Exam_service examService;
|
|
|
|
|
@ -49,13 +51,13 @@ public class MainFrame extends JFrame {
|
|
|
|
|
createGradeSelectionPanel();
|
|
|
|
|
createExamPanel();
|
|
|
|
|
createResultPanel();
|
|
|
|
|
createWrongQuestionsPanel(); // 新增错题面板
|
|
|
|
|
createPasswordChangePanel();
|
|
|
|
|
|
|
|
|
|
add(mainPanel);
|
|
|
|
|
showLoginPanel();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 其他面板创建方法保持不变...
|
|
|
|
|
private void createLoginPanel() {
|
|
|
|
|
JPanel panel = new JPanel(new BorderLayout(10, 10));
|
|
|
|
|
panel.setBorder(BorderFactory.createEmptyBorder(50, 100, 50, 100));
|
|
|
|
|
@ -254,19 +256,58 @@ public class MainFrame extends JFrame {
|
|
|
|
|
|
|
|
|
|
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 30, 20));
|
|
|
|
|
|
|
|
|
|
// 新增查看错题按钮
|
|
|
|
|
JButton reviewButton = createStyledButton("查看错题");
|
|
|
|
|
reviewButton.addActionListener(e -> showWrongQuestions());
|
|
|
|
|
buttonPanel.add(reviewButton);
|
|
|
|
|
|
|
|
|
|
JButton continueButton = createStyledButton("继续做题");
|
|
|
|
|
continueButton.addActionListener(e -> showGradeSelectionPanel());
|
|
|
|
|
buttonPanel.add(continueButton);
|
|
|
|
|
|
|
|
|
|
JButton exitButton = createStyledButton("退出程序");
|
|
|
|
|
exitButton.addActionListener(e -> System.exit(0));
|
|
|
|
|
|
|
|
|
|
buttonPanel.add(continueButton);
|
|
|
|
|
buttonPanel.add(exitButton);
|
|
|
|
|
|
|
|
|
|
panel.add(buttonPanel, BorderLayout.SOUTH);
|
|
|
|
|
|
|
|
|
|
mainPanel.add(panel, "Result");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void createWrongQuestionsPanel() {
|
|
|
|
|
JPanel panel = new JPanel(new BorderLayout(10, 10));
|
|
|
|
|
panel.setBorder(BorderFactory.createEmptyBorder(20, 40, 20, 40));
|
|
|
|
|
|
|
|
|
|
// 标题
|
|
|
|
|
JLabel titleLabel = new JLabel("错题回顾", JLabel.CENTER);
|
|
|
|
|
titleLabel.setFont(new Font("微软雅黑", Font.BOLD, 20));
|
|
|
|
|
panel.add(titleLabel, BorderLayout.NORTH);
|
|
|
|
|
|
|
|
|
|
// 错题内容区域(使用滚动面板)
|
|
|
|
|
JTextArea wrongQuestionsArea = new JTextArea();
|
|
|
|
|
wrongQuestionsArea.setFont(new Font("微软雅黑", Font.PLAIN, 14));
|
|
|
|
|
wrongQuestionsArea.setEditable(false);
|
|
|
|
|
wrongQuestionsArea.setLineWrap(true);
|
|
|
|
|
wrongQuestionsArea.setWrapStyleWord(true);
|
|
|
|
|
|
|
|
|
|
JScrollPane scrollPane = new JScrollPane(wrongQuestionsArea);
|
|
|
|
|
scrollPane.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
|
|
|
|
|
panel.add(scrollPane, BorderLayout.CENTER);
|
|
|
|
|
|
|
|
|
|
// 存储错题文本区域引用
|
|
|
|
|
panel.putClientProperty("wrongQuestionsArea", wrongQuestionsArea);
|
|
|
|
|
|
|
|
|
|
// 返回按钮
|
|
|
|
|
JPanel bottomPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
|
|
|
|
|
JButton backButton = createStyledButton("返回成绩");
|
|
|
|
|
backButton.addActionListener(e -> showResultPanel());
|
|
|
|
|
bottomPanel.add(backButton);
|
|
|
|
|
|
|
|
|
|
panel.add(bottomPanel, BorderLayout.SOUTH);
|
|
|
|
|
|
|
|
|
|
mainPanel.add(panel, "WrongQuestions");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void createPasswordChangePanel() {
|
|
|
|
|
JPanel panel = new JPanel(new BorderLayout(10, 10));
|
|
|
|
|
panel.setBorder(BorderFactory.createEmptyBorder(50, 100, 50, 100));
|
|
|
|
|
@ -365,6 +406,10 @@ public class MainFrame extends JFrame {
|
|
|
|
|
cardLayout.show(mainPanel, "Result");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void showWrongQuestionsPanel() {
|
|
|
|
|
cardLayout.show(mainPanel, "WrongQuestions");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 业务逻辑方法
|
|
|
|
|
private void login() {
|
|
|
|
|
String id = loginIdField.getText().trim();
|
|
|
|
|
@ -442,7 +487,6 @@ public class MainFrame extends JFrame {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 关键修改:使用Question类的实际方法
|
|
|
|
|
private void showCurrentQuestion() {
|
|
|
|
|
Question question = examService.get_now_question();
|
|
|
|
|
if (question != null) {
|
|
|
|
|
@ -452,17 +496,14 @@ public class MainFrame extends JFrame {
|
|
|
|
|
questionNumberLabel.setText(String.format("第 %d 题 / 共 %d 题",
|
|
|
|
|
currentIndex + 1, totalQuestions));
|
|
|
|
|
|
|
|
|
|
// 使用Question类的toString()方法显示题目
|
|
|
|
|
questionLabel.setText("<html><div style='text-align: center; font-size: 16px;'>" +
|
|
|
|
|
question.toString() + "</div></html>");
|
|
|
|
|
|
|
|
|
|
// 使用Question类的getOptions方法显示选项
|
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
|
String optionText = question.getOptions(i);
|
|
|
|
|
optionButtons[i].setText("选项 " + (char)('A' + i) + ": " + optionText);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 恢复用户已选择的答案
|
|
|
|
|
Integer userAnswer = examService.get_user_answer(currentIndex);
|
|
|
|
|
optionGroup.clearSelection();
|
|
|
|
|
if (userAnswer != null && userAnswer >= 0 && userAnswer < 4) {
|
|
|
|
|
@ -523,7 +564,6 @@ public class MainFrame extends JFrame {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 关键修改:使用Exam_result类的实际方法显示详细结果
|
|
|
|
|
private void showExamResult() {
|
|
|
|
|
Exam_result result = examService.calculate_result();
|
|
|
|
|
|
|
|
|
|
@ -549,6 +589,63 @@ public class MainFrame extends JFrame {
|
|
|
|
|
showResultPanel();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 新增:查看错题功能
|
|
|
|
|
// 修正:查看错题功能 - 简洁显示
|
|
|
|
|
private void showWrongQuestions() {
|
|
|
|
|
// 获取考试结果
|
|
|
|
|
Exam_result result = examService.calculate_result();
|
|
|
|
|
java.util.List<Integer> wrongQuestionIndices = result.getWrongQuestions();
|
|
|
|
|
|
|
|
|
|
if (wrongQuestionIndices.isEmpty()) {
|
|
|
|
|
JOptionPane.showMessageDialog(this, "恭喜!本次考试没有错题!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取错题面板和文本区域
|
|
|
|
|
JPanel wrongQuestionsPanel = (JPanel) mainPanel.getComponent(5); // 第6个面板是错题面板
|
|
|
|
|
JTextArea wrongQuestionsArea = (JTextArea) ((JScrollPane) wrongQuestionsPanel.getComponent(1)).getViewport().getView();
|
|
|
|
|
|
|
|
|
|
// 构建错题显示内容
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
sb.append("本次考试共有 ").append(wrongQuestionIndices.size()).append(" 道错题:\n\n");
|
|
|
|
|
|
|
|
|
|
java.util.ArrayList<Question> paper = examService.get_paper();
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < wrongQuestionIndices.size(); i++) {
|
|
|
|
|
int questionIndex = wrongQuestionIndices.get(i);
|
|
|
|
|
Question question = paper.get(questionIndex);
|
|
|
|
|
|
|
|
|
|
// 只显示一个题号
|
|
|
|
|
sb.append("第 ").append(questionIndex + 1).append(" 题:");
|
|
|
|
|
sb.append(question.toString()).append("\n");
|
|
|
|
|
|
|
|
|
|
// 显示所有选项,在正确答案后打勾
|
|
|
|
|
sb.append("选项:\n");
|
|
|
|
|
for (int j = 0; j < 4; j++) {
|
|
|
|
|
char optionChar = (char) ('A' + j);
|
|
|
|
|
sb.append(" ").append(optionChar).append(". ").append(question.getOptions(j));
|
|
|
|
|
|
|
|
|
|
// 标记正确答案
|
|
|
|
|
if (question.getOptions(j).equals(question.getAnswer())) {
|
|
|
|
|
sb.append(" √");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 标记用户选择的错误答案
|
|
|
|
|
Integer userAnswer = examService.get_user_answer(questionIndex);
|
|
|
|
|
if (userAnswer != null && userAnswer == j && !question.getOptions(j).equals(question.getAnswer())) {
|
|
|
|
|
sb.append(" X");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sb.append("\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sb.append("\n");
|
|
|
|
|
sb.append("-".repeat(50)).append("\n\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wrongQuestionsArea.setText(sb.toString());
|
|
|
|
|
showWrongQuestionsPanel();
|
|
|
|
|
}
|
|
|
|
|
private void changePassword(String email, String oldPassword, String newPassword, String confirmPassword) {
|
|
|
|
|
if (email.isEmpty() || oldPassword.isEmpty() || newPassword.isEmpty()) {
|
|
|
|
|
JOptionPane.showMessageDialog(this, "请填写所有字段");
|
|
|
|
|
@ -573,4 +670,11 @@ public class MainFrame extends JFrame {
|
|
|
|
|
examService = null;
|
|
|
|
|
showLoginPanel();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 主函数
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
SwingUtilities.invokeLater(() -> {
|
|
|
|
|
new MainFrame().setVisible(true);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|