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; } }