|
|
|
|
@ -2,8 +2,9 @@ package controller;
|
|
|
|
|
|
|
|
|
|
import ui.LoginPanel;
|
|
|
|
|
import ui.RegisterPanel;
|
|
|
|
|
import ui.DifficultySelectionPanel; // 添加难度选择面板
|
|
|
|
|
import view.QuizPanel; // 保持原有导入
|
|
|
|
|
import ui.DifficultySelectionPanel;
|
|
|
|
|
import model.User;
|
|
|
|
|
import view.QuizPanel;
|
|
|
|
|
|
|
|
|
|
import javax.swing.*;
|
|
|
|
|
import java.awt.*;
|
|
|
|
|
@ -28,7 +29,6 @@ public class AppController {
|
|
|
|
|
frame.setVisible(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 显示登录界面 */
|
|
|
|
|
public void showLoginPanel() {
|
|
|
|
|
frame.getContentPane().removeAll();
|
|
|
|
|
frame.add(new LoginPanel(this));
|
|
|
|
|
@ -36,7 +36,6 @@ public class AppController {
|
|
|
|
|
frame.repaint();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 显示注册界面 */
|
|
|
|
|
public void showRegisterPanel() {
|
|
|
|
|
frame.getContentPane().removeAll();
|
|
|
|
|
frame.add(new RegisterPanel(this));
|
|
|
|
|
@ -44,7 +43,6 @@ public class AppController {
|
|
|
|
|
frame.repaint();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 显示难度选择界面 */
|
|
|
|
|
public void showDifficultySelectionPanel() {
|
|
|
|
|
frame.getContentPane().removeAll();
|
|
|
|
|
frame.add(new DifficultySelectionPanel(this));
|
|
|
|
|
@ -52,7 +50,6 @@ public class AppController {
|
|
|
|
|
frame.repaint();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 显示题目选择界面(QuizPanel) */
|
|
|
|
|
public void showQuizPanel(String level, int count) {
|
|
|
|
|
frame.getContentPane().removeAll();
|
|
|
|
|
frame.add(new QuizPanel(this, level, count));
|
|
|
|
|
@ -60,31 +57,31 @@ public class AppController {
|
|
|
|
|
frame.repaint();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 登录逻辑 */
|
|
|
|
|
public void handleLogin(String email, String password) {
|
|
|
|
|
if (userManager.checkLogin(email, password)) {
|
|
|
|
|
JOptionPane.showMessageDialog(frame, "登录成功!");
|
|
|
|
|
// 跳转到难度选择界面
|
|
|
|
|
// 获取用户并显示注册的用户名
|
|
|
|
|
User user = userManager.getUserByEmail(email);
|
|
|
|
|
String displayName = user != null ? user.getUsername() : email;
|
|
|
|
|
JOptionPane.showMessageDialog(frame, "欢迎回来," + displayName + "!");
|
|
|
|
|
showDifficultySelectionPanel();
|
|
|
|
|
} else {
|
|
|
|
|
JOptionPane.showMessageDialog(frame, "邮箱或密码错误!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 注册逻辑 */
|
|
|
|
|
public void handleRegister(String email, String password) {
|
|
|
|
|
public void handleRegister(String email, String password, String username) {
|
|
|
|
|
if (userManager.isUserExist(email)) {
|
|
|
|
|
JOptionPane.showMessageDialog(frame, "该邮箱已注册!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
userManager.addUser(email, password);
|
|
|
|
|
// 传递 username 参数
|
|
|
|
|
userManager.addUser(email, password, username);
|
|
|
|
|
JOptionPane.showMessageDialog(frame, "注册成功!请登录。");
|
|
|
|
|
showLoginPanel();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 在难度选择界面处理难度选择 */
|
|
|
|
|
public void handleDifficultySelection(String level) {
|
|
|
|
|
// 弹出输入框要求输入题目数量
|
|
|
|
|
String countInput = JOptionPane.showInputDialog(
|
|
|
|
|
frame,
|
|
|
|
|
"请输入需要生成的题目数量 (1-50):",
|
|
|
|
|
@ -93,7 +90,6 @@ public class AppController {
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (countInput == null) {
|
|
|
|
|
// 用户取消输入
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -103,7 +99,6 @@ public class AppController {
|
|
|
|
|
JOptionPane.showMessageDialog(frame, "题目数量必须在1-50之间!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// 跳转到题目界面
|
|
|
|
|
showQuizPanel(level, count);
|
|
|
|
|
} catch (NumberFormatException e) {
|
|
|
|
|
JOptionPane.showMessageDialog(frame, "请输入有效的数字!");
|
|
|
|
|
|