From 97bc817e602ce0dc751428b20145553e396429cf Mon Sep 17 00:00:00 2001 From: pus7f45rn <2668148347@qq.com> Date: Sun, 12 Oct 2025 17:29:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E8=87=B3?= =?UTF-8?q?=20'src/view'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/view/ScoreView.java | 52 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/view/ScoreView.java diff --git a/src/view/ScoreView.java b/src/view/ScoreView.java new file mode 100644 index 0000000..f389431 --- /dev/null +++ b/src/view/ScoreView.java @@ -0,0 +1,52 @@ +package view; + +import javax.swing.*; +import javax.swing.border.EmptyBorder; +import java.awt.*; + +public class ScoreView extends JPanel { + private final JLabel scoreLabel = new JLabel("0", SwingConstants.CENTER); + private final JLabel scoreUnitLabel = new JLabel("分", SwingConstants.CENTER); + private final JLabel detailLabel = new JLabel(" ", SwingConstants.CENTER); + private final JButton continueButton = new JButton("再来一组"); + private final JButton exitButton = new JButton("退出登录"); + + public ScoreView() { + setLayout(new GridBagLayout()); + GridBagConstraints gbc = new GridBagConstraints(); + gbc.gridwidth = GridBagConstraints.REMAINDER; + gbc.insets = new Insets(10, 10, 10, 10); + + JLabel titleLabel = new JLabel("答题结束!", SwingConstants.CENTER); + titleLabel.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 32)); + add(titleLabel, gbc); + + JPanel scorePanel = new JPanel(); + scoreLabel.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 100)); + scoreUnitLabel.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 30)); + scoreUnitLabel.setBorder(new EmptyBorder(0,0, -50, 0)); + scorePanel.add(scoreLabel); + scorePanel.add(scoreUnitLabel); + add(scorePanel, gbc); + + detailLabel.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 20)); + add(detailLabel, gbc); + + JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 20, 0)); + continueButton.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 16)); + // 【修复】将 "=" 修改为 ":" + continueButton.putClientProperty("JButton.buttonType", "roundRect"); + buttonPanel.add(continueButton); + buttonPanel.add(exitButton); + gbc.insets = new Insets(30, 10, 10, 10); + add(buttonPanel, gbc); + } + + public void setScore(int score, int correct, int total) { + scoreLabel.setText(String.valueOf(score)); + detailLabel.setText(String.format("答对 %d 题,共 %d 题", correct, total)); + } + + public JButton getContinueButton() { return continueButton; } + public JButton getExitButton() { return exitButton; } +} \ No newline at end of file