parent
b02f4178c0
commit
b340f6960b
@ -1 +1 @@
|
||||
User.java
|
||||
UserService.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) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue