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.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
package controller ;
import ui.LoginPanel ;
import ui.RegisterPanel ;
import javax.swing.* ;
import java.awt.* ;
/**
* 控制器:负责界面切换与核心逻辑
*/
public class AppController {
private JFrame frame ;
private UserManager userManager ;
public AppController ( ) {
userManager = new UserManager ( ) ;
frame = new JFrame ( "学生数学学习系统" ) ;
frame . setDefaultCloseOperation ( JFrame . EXIT_ON_CLOSE ) ;
frame . setSize ( 450 , 400 ) ;
frame . setLocationRelativeTo ( null ) ;
frame . setLayout ( new BorderLayout ( ) ) ;
showLoginPanel ( ) ;
frame . setVisible ( true ) ;
}
/** 显示登录界面 */
public void showLoginPanel ( ) {
frame . getContentPane ( ) . removeAll ( ) ;
frame . add ( new LoginPanel ( this ) ) ;
frame . revalidate ( ) ;
frame . repaint ( ) ;
}
/** 显示注册界面 */
public void showRegisterPanel ( ) {
frame . getContentPane ( ) . removeAll ( ) ;
frame . add ( new RegisterPanel ( this ) ) ;
frame . revalidate ( ) ;
frame . repaint ( ) ;
}
/** 登录逻辑 */
public void handleLogin ( String email , String password ) {
if ( userManager . checkLogin ( email , password ) ) {
JOptionPane . showMessageDialog ( frame , "登录成功!" ) ;
// TODO: 跳转到题目选择界面( QuizPanel)
} else {
JOptionPane . showMessageDialog ( frame , "邮箱或密码错误!" ) ;
}
}
/** 注册逻辑 */
public void handleRegister ( String email , String password ) {
if ( userManager . isUserExist ( email ) ) {
JOptionPane . showMessageDialog ( frame , "该邮箱已注册!" ) ;
return ;
}
userManager . addUser ( email , password ) ;
JOptionPane . showMessageDialog ( frame , "注册成功!请登录。" ) ;
showLoginPanel ( ) ;
}
}