From 08d84e805a8eebdec54d1b62a4e33938a1eacc95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=98=A0=E6=B1=9F?= <15547749+cyj-050209@user.noreply.gitee.com> Date: Thu, 9 Oct 2025 21:22:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=B8=BB=E8=8F=9C=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/.name | 2 +- data/users.json | 2 +- src/main/java/mathlearning/ui/LoginFrame.java | 9 +- src/main/java/mathlearning/ui/MainFrame.java | 137 ++++++++++++++++++ 4 files changed, 146 insertions(+), 4 deletions(-) create mode 100644 src/main/java/mathlearning/ui/MainFrame.java diff --git a/.idea/.name b/.idea/.name index 340ca5b..4f2c764 100644 --- a/.idea/.name +++ b/.idea/.name @@ -1 +1 @@ -User.java \ No newline at end of file +UserService.java \ No newline at end of file diff --git a/data/users.json b/data/users.json index 78be335..2c43fb0 100644 --- a/data/users.json +++ b/data/users.json @@ -5,5 +5,5 @@ "registrationDate" : [ 2025, 10, 8, 21, 0, 37, 863490500 ], "verificationCode" : "926911", "verified" : true, - "type" : "初中" + "type" : "小学" } ] \ No newline at end of file diff --git a/src/main/java/mathlearning/ui/LoginFrame.java b/src/main/java/mathlearning/ui/LoginFrame.java index d42000c..b2f5a96 100644 --- a/src/main/java/mathlearning/ui/LoginFrame.java +++ b/src/main/java/mathlearning/ui/LoginFrame.java @@ -157,7 +157,12 @@ public class LoginFrame extends JFrame{ "登录成功", JOptionPane.INFORMATION_MESSAGE); } - // 后续可以在这里打开主界面 - // openMainApplicationWindow(user); + openMainApplicationWindow(user, userService); + } + + private void openMainApplicationWindow(User user, UserService userService) { + MainFrame mainFrame = new MainFrame(user, userService); + mainFrame.setVisible(true); + dispose(); } } diff --git a/src/main/java/mathlearning/ui/MainFrame.java b/src/main/java/mathlearning/ui/MainFrame.java new file mode 100644 index 0000000..8072cb1 --- /dev/null +++ b/src/main/java/mathlearning/ui/MainFrame.java @@ -0,0 +1,137 @@ +package mathlearning.ui; + +import com.sun.tools.javac.Main; +import mathlearning.model.User; +import mathlearning.service.UserService; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +public class MainFrame extends JFrame { + private User currentUser; + private UserService userService; + private JLabel welcomeLabel; + private JLabel typeLabel; + + public MainFrame(User user, UserService userService) { + this.currentUser = user; + this.userService = userService; + InitializeUI(); + } + + private void InitializeUI() { + setTitle("数学学习软件 - 菜单"); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setSize(500, 400); + setLocationRelativeTo(null); + setResizable(false); + + // 主面板 + JPanel titlePanel = new JPanel(new BorderLayout()); + JPanel mainPanel = new JPanel(new BorderLayout(10, 10)); + mainPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); + + // 欢迎用户与type信息 + welcomeLabel = new JLabel("欢迎"+currentUser.getUsername()+"!", JLabel.CENTER); + welcomeLabel.setFont(new Font("微软雅黑", Font.BOLD, 24)); + + typeLabel = new JLabel("当前选择的测试题为" + currentUser.getType() + "难度", JLabel.CENTER); + typeLabel.setFont(new Font("微软雅黑", Font.BOLD, 16)); + typeLabel.setForeground(Color.BLUE); + + titlePanel.add(welcomeLabel, BorderLayout.NORTH); + titlePanel.add(typeLabel, BorderLayout.CENTER); + mainPanel.add(titlePanel, BorderLayout.NORTH); + + // 功能按钮区域 + JPanel centerButtonPanel = new JPanel(new GridLayout(2, 1, 15, 15)); + centerButtonPanel.setBorder(BorderFactory.createEmptyBorder(30, 50, 30, 50)); + // 切换教育阶段按钮 + JButton changeTypeButton = new JButton("切换教育阶段"); + changeTypeButton.setFont(new Font("微软雅黑", Font.BOLD, 18)); + changeTypeButton.setBackground(new Color(70, 130, 180)); + changeTypeButton.setForeground(Color.WHITE); + changeTypeButton.setPreferredSize(new Dimension(200, 60)); + changeTypeButton.addActionListener(new ChangeTypeListener()); + + // 自我测试按钮 + JButton selfTestButton = new JButton("自我测试"); + selfTestButton.setFont(new Font("微软雅黑", Font.BOLD, 18)); + selfTestButton.setBackground(new Color(34, 139, 34)); + selfTestButton.setForeground(Color.WHITE); + selfTestButton.setPreferredSize(new Dimension(200, 60)); + //selfTestButton.addActionListener(new SelfTestListener()); + + centerButtonPanel.add(changeTypeButton); + centerButtonPanel.add(selfTestButton); + mainPanel.add(centerButtonPanel, BorderLayout.CENTER); + + // 底部按钮面板 - 两个较小按钮 + JPanel bottomButtonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 20, 10)); + + // 退出登录按钮 + JButton logoutButton = new JButton("退出登录"); + logoutButton.setFont(new Font("微软雅黑", Font.PLAIN, 14)); + logoutButton.setBackground(new Color(220, 20, 60)); + logoutButton.setForeground(Color.WHITE); + logoutButton.addActionListener(new LogoutListener()); + + // 个人资料按钮 + JButton profileButton = new JButton("个人资料"); + profileButton.setFont(new Font("微软雅黑", Font.PLAIN, 14)); + profileButton.setBackground(new Color(100, 149, 237)); + profileButton.setForeground(Color.WHITE); + profileButton.addActionListener(new ProfileListener()); + + bottomButtonPanel.add(logoutButton); + bottomButtonPanel.add(profileButton); + mainPanel.add(bottomButtonPanel, BorderLayout.SOUTH); + + add(mainPanel); + } + + private class ChangeTypeListener implements ActionListener { + @Override + public void actionPerformed(ActionEvent e) { + String[] types = {"小学", "初中", "高中" }; + String selectedType = (String) JOptionPane.showInputDialog(MainFrame.this, "请选择需要切换的难度:", "选择难度", JOptionPane.QUESTION_MESSAGE, null, types, currentUser.getType()); + if (selectedType != null) { + boolean updated = userService.updateUserType(currentUser.getEmail(), selectedType); + + if (updated) { + currentUser.setType(selectedType); + JOptionPane.showMessageDialog(MainFrame.this, "当前难度已更改为" + currentUser.getType() , "切换成功", JOptionPane.INFORMATION_MESSAGE); + updateTypeDisplay(); + } else { + JOptionPane.showMessageDialog(MainFrame.this, "切换失败", "错误", JOptionPane.ERROR_MESSAGE); + } + } + } + } + + private void updateTypeDisplay() { + typeLabel.setText("当前选择的测试题为" + currentUser.getType() + "难度"); + } + + private class LogoutListener implements ActionListener { + @Override + public void actionPerformed(ActionEvent e) { + int result = JOptionPane.showConfirmDialog(MainFrame.this, "确定要退出登陆吗?", "退出登录", JOptionPane.YES_NO_OPTION); + + if (result == JOptionPane.YES_OPTION) { + LoginFrame loginFrame = new LoginFrame(userService); + loginFrame.setVisible(true); + dispose(); + } + } + } + + private class ProfileListener implements ActionListener { + @Override + public void actionPerformed(ActionEvent e) { + + } + } +}