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.
60 lines
1.9 KiB
60 lines
1.9 KiB
package view;
|
|
|
|
import controller.ExamController;
|
|
import javax.swing.JFrame;
|
|
import javax.swing.JPanel;
|
|
import javax.swing.JLabel;
|
|
import javax.swing.JButton;
|
|
import java.awt.BorderLayout;
|
|
import java.awt.GridLayout;
|
|
import java.awt.Font;
|
|
|
|
public class ResultFrame extends JFrame {
|
|
public ResultFrame(ExamController controller, int score, int total) {
|
|
setTitle("考试结果");
|
|
setSize(300, 200);
|
|
setLocationRelativeTo(null);
|
|
|
|
JPanel panel = new JPanel(new BorderLayout());
|
|
|
|
// 创建结果信息面板
|
|
JPanel resultPanel = new JPanel(new GridLayout(3, 1));
|
|
JLabel scoreLabel = new JLabel("得分: " + score + "/" + total, JLabel.CENTER);
|
|
JLabel totalLabel = new JLabel("总题数: " + total + "题", JLabel.CENTER);
|
|
double percentage = (double) score / total * 100;
|
|
JLabel percentageLabel = new JLabel(String.format("正确率: %.1f%%", percentage), JLabel.CENTER);
|
|
|
|
// 设置字体
|
|
Font boldFont = new Font("微软雅黑", Font.BOLD, 16);
|
|
scoreLabel.setFont(boldFont);
|
|
totalLabel.setFont(new Font("微软雅黑", Font.PLAIN, 14));
|
|
percentageLabel.setFont(new Font("微软雅黑", Font.PLAIN, 14));
|
|
|
|
resultPanel.add(scoreLabel);
|
|
resultPanel.add(totalLabel);
|
|
resultPanel.add(percentageLabel);
|
|
|
|
JButton continueBtn = new JButton("继续做题");
|
|
JButton exitBtn = new JButton("退出");
|
|
|
|
continueBtn.addActionListener(e -> {
|
|
dispose();
|
|
controller.returnToMain();
|
|
});
|
|
|
|
exitBtn.addActionListener(e -> {
|
|
dispose();
|
|
controller.returnToMain();
|
|
});
|
|
|
|
JPanel buttonPanel = new JPanel();
|
|
buttonPanel.add(continueBtn);
|
|
buttonPanel.add(exitBtn);
|
|
|
|
panel.add(resultPanel, BorderLayout.CENTER);
|
|
panel.add(buttonPanel, BorderLayout.SOUTH);
|
|
|
|
add(panel);
|
|
setVisible(true);
|
|
}
|
|
} |