You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
math_question/controller/MainController.java

93 lines
2.0 KiB

package controller;
import view.*;
public class MainController {
private AuthController authController = new AuthController(this);
private ExamController examController = new ExamController(this);
private MainFrame mainFrame;
public MainController() {
// 控制器初始化
}
/**
* 显示登录界面
*/
public void showLogin() {
// 如果主界面存在,先关闭它
if (mainFrame != null) {
mainFrame.dispose();
mainFrame = null;
}
// 创建并显示登录界面
new LoginFrame(authController);
}
/**
* 显示主界面
*/
public void showMainFrame() {
if (mainFrame == null) {
// 第一次显示,创建主界面
mainFrame = new MainFrame(this);
}
// 显示主界面
mainFrame.showFrame();
// 确保主界面位于前台
mainFrame.toFront();
mainFrame.requestFocus();
}
/**
* 开始考试
* @param difficulty 考试难度
*/
public void startExam(String difficulty) {
examController.startExam(difficulty);
}
/**
* 退出登录
*/
public void logout() {
// 清理主界面
if (mainFrame != null) {
mainFrame.dispose();
mainFrame = null;
}
// 显示登录界面
showLogin();
}
/**
* 获取认证控制器
*/
public AuthController getAuthController() {
return authController;
}
/**
* 获取考试控制器
*/
public ExamController getExamController() {
return examController;
}
/**
* 获取主界面实例(用于特殊操作)
*/
public MainFrame getMainFrame() {
return mainFrame;
}
/**
* 应用程序退出
*/
public void exitApplication() {
// 清理资源
if (mainFrame != null) {
mainFrame.dispose();
}
System.exit(0);
}
}