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.
127 lines
3.8 KiB
127 lines
3.8 KiB
package ui;
|
|
|
|
import model.Grade;
|
|
import javax.swing.BorderFactory;
|
|
import javax.swing.JButton;
|
|
import javax.swing.JFrame;
|
|
import javax.swing.JLabel;
|
|
import javax.swing.JPanel;
|
|
import java.awt.BorderLayout;
|
|
import java.awt.Color;
|
|
import java.awt.Dimension;
|
|
import java.awt.FlowLayout;
|
|
import java.awt.Font;
|
|
import java.awt.GridBagConstraints;
|
|
import java.awt.GridBagLayout;
|
|
import java.awt.Insets;
|
|
|
|
/**
|
|
* 答题结果展示界面
|
|
* 显示得分和统计信息,提供继续答题或退出选项
|
|
*/
|
|
public class ResultFrame extends JFrame {
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
private final String email;
|
|
private final Grade gradeType;
|
|
|
|
/**
|
|
* 构造结果展示界面
|
|
*
|
|
* @param email 用户邮箱
|
|
* @param gradeType 年级类型
|
|
* @param score 得分
|
|
* @param correctCount 答对题数
|
|
* @param totalCount 总题数
|
|
*/
|
|
public ResultFrame(String email, Grade gradeType, int score,
|
|
int correctCount, int totalCount) {
|
|
this.email = email;
|
|
this.gradeType = gradeType;
|
|
|
|
setTitle("数学学习软件 - 答题结果");
|
|
setSize(600, 420);
|
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
setLocationRelativeTo(null);
|
|
setResizable(true);
|
|
|
|
JPanel mainPanel = new JPanel(new BorderLayout(10, 10));
|
|
mainPanel.setBorder(BorderFactory.createEmptyBorder(30, 30, 30, 30));
|
|
|
|
JPanel centerPanel = new JPanel(new GridBagLayout());
|
|
GridBagConstraints gbc = new GridBagConstraints();
|
|
gbc.insets = new Insets(10, 10, 10, 10);
|
|
gbc.gridx = 0;
|
|
gbc.gridy = 0;
|
|
|
|
JLabel titleLabel = new JLabel("答题完成!", JLabel.CENTER);
|
|
titleLabel.setFont(new Font("微软雅黑", Font.BOLD, 24));
|
|
centerPanel.add(titleLabel, gbc);
|
|
|
|
gbc.gridy = 1;
|
|
JLabel scoreLabel = new JLabel("得分: " + score, JLabel.CENTER);
|
|
scoreLabel.setFont(new Font("微软雅黑", Font.BOLD, 36));
|
|
scoreLabel.setForeground(getScoreColor(score));
|
|
centerPanel.add(scoreLabel, gbc);
|
|
|
|
gbc.gridy = 2;
|
|
JLabel detailLabel = new JLabel(
|
|
String.format("答对 %d 题 / 共 %d 题", correctCount, totalCount),
|
|
JLabel.CENTER);
|
|
detailLabel.setFont(new Font("微软雅黑", Font.PLAIN, 14));
|
|
centerPanel.add(detailLabel, gbc);
|
|
|
|
mainPanel.add(centerPanel, BorderLayout.CENTER);
|
|
|
|
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 15, 0));
|
|
JButton continueButton = new JButton("继续做题");
|
|
JButton exitButton = new JButton("退出");
|
|
|
|
continueButton.setPreferredSize(new Dimension(120, 35));
|
|
exitButton.setPreferredSize(new Dimension(120, 35));
|
|
|
|
buttonPanel.add(continueButton);
|
|
buttonPanel.add(exitButton);
|
|
|
|
mainPanel.add(buttonPanel, BorderLayout.SOUTH);
|
|
|
|
add(mainPanel);
|
|
|
|
continueButton.addActionListener(e -> continueQuiz());
|
|
exitButton.addActionListener(e -> exitToSelection());
|
|
}
|
|
|
|
/**
|
|
* 根据分数返回对应颜色
|
|
*
|
|
* @param score 分数
|
|
* @return 颜色对象
|
|
*/
|
|
private Color getScoreColor(int score) {
|
|
if (score >= 90) {
|
|
return new Color(0, 150, 0);
|
|
} else if (score >= 60) {
|
|
return new Color(255, 140, 0);
|
|
} else {
|
|
return new Color(200, 0, 0);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 继续做题
|
|
*/
|
|
private void continueQuiz() {
|
|
GradeSelectionFrame frame = new GradeSelectionFrame(email, gradeType);
|
|
frame.setVisible(true);
|
|
this.dispose();
|
|
}
|
|
|
|
/**
|
|
* 退出到选择界面
|
|
*/
|
|
private void exitToSelection() {
|
|
GradeSelectionFrame frame = new GradeSelectionFrame(email, gradeType);
|
|
frame.setVisible(true);
|
|
this.dispose();
|
|
}
|
|
} |