package com.mathlearning.view; import com.mathlearning.controller.NavigationController; import javax.swing.*; import java.awt.*; public class LevelSelectionView extends JPanel { private NavigationController navigationController; private String userIdentifier; private String email; private JButton primaryButton; private JButton middleButton; private JButton highButton; private JButton logoutButton; public LevelSelectionView(NavigationController navigationController, String userIdentifier, String email) { this.navigationController = navigationController; this.userIdentifier = userIdentifier; this.email = email; initializeUI(); } private void initializeUI() { setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.insets = new Insets(15, 15, 15, 15); gbc.fill = GridBagConstraints.HORIZONTAL; JLabel titleLabel = new JLabel("选择学习阶段", JLabel.CENTER); titleLabel.setFont(new Font("微软雅黑", Font.BOLD, 24)); gbc.gridx = 0; gbc.gridy = 0; gbc.gridwidth = 2; add(titleLabel, gbc); gbc.gridy = 1; String userInfo = "当前用户: " + userIdentifier; if (!userIdentifier.equals(email)) { userInfo += " (" + email + ")"; } JLabel userLabel = new JLabel(userInfo, JLabel.CENTER); userLabel.setFont(new Font("微软雅黑", Font.PLAIN, 14)); add(userLabel, gbc); gbc.gridwidth = 1; gbc.gridx = 0; gbc.gridy = 2; primaryButton = new JButton("小学"); primaryButton.setFont(new Font("微软雅黑", Font.PLAIN, 18)); primaryButton.addActionListener(e -> navigationController.showQuestionCountView("小学")); add(primaryButton, gbc); gbc.gridx = 1; gbc.gridy = 2; middleButton = new JButton("初中"); middleButton.setFont(new Font("微软雅黑", Font.PLAIN, 18)); middleButton.addActionListener(e -> navigationController.showQuestionCountView("初中")); add(middleButton, gbc); gbc.gridx = 0; gbc.gridy = 3; gbc.gridwidth = 2; highButton = new JButton("高中"); highButton.setFont(new Font("微软雅黑", Font.PLAIN, 18)); highButton.addActionListener(e -> navigationController.showQuestionCountView("高中")); add(highButton, gbc); gbc.gridy = 4; logoutButton = new JButton("退出登录"); logoutButton.addActionListener(e -> navigationController.showLoginView()); add(logoutButton, gbc); } }