|
|
|
|
@ -4,19 +4,26 @@ import controller.NavigationController;
|
|
|
|
|
import controller.UserController;
|
|
|
|
|
import model.User;
|
|
|
|
|
|
|
|
|
|
import javax.swing.*;
|
|
|
|
|
import javax.swing.JFrame;
|
|
|
|
|
import javax.swing.JPanel;
|
|
|
|
|
import javax.swing.JLabel;
|
|
|
|
|
import javax.swing.JTextField;
|
|
|
|
|
import javax.swing.JPasswordField;
|
|
|
|
|
import javax.swing.JButton;
|
|
|
|
|
import javax.swing.BorderFactory;
|
|
|
|
|
import javax.swing.JOptionPane;
|
|
|
|
|
import java.awt.*;
|
|
|
|
|
import java.awt.event.ActionEvent;
|
|
|
|
|
import java.awt.event.ActionListener;
|
|
|
|
|
|
|
|
|
|
public class RegisterView extends JFrame {
|
|
|
|
|
private JTextField usernameField; // 新增:用户名输入框
|
|
|
|
|
private JTextField usernameField;
|
|
|
|
|
private JTextField emailField;
|
|
|
|
|
private JTextField codeField;
|
|
|
|
|
private JPasswordField passwordField;
|
|
|
|
|
private JPasswordField confirmPasswordField;
|
|
|
|
|
private UserController userController;
|
|
|
|
|
private String currentUsername; // 保存当前注册的用户名
|
|
|
|
|
private String currentUsername;
|
|
|
|
|
|
|
|
|
|
public RegisterView() {
|
|
|
|
|
userController = new UserController();
|
|
|
|
|
@ -26,7 +33,7 @@ public class RegisterView extends JFrame {
|
|
|
|
|
private void initializeUI() {
|
|
|
|
|
setTitle("数学学习软件 - 注册");
|
|
|
|
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
|
|
|
setSize(550, 500); // 增加高度以容纳用户名字段
|
|
|
|
|
setSize(550, 550); // 增加高度以容纳所有组件
|
|
|
|
|
setLocationRelativeTo(null);
|
|
|
|
|
setResizable(false);
|
|
|
|
|
|
|
|
|
|
@ -38,8 +45,8 @@ public class RegisterView extends JFrame {
|
|
|
|
|
titleLabel.setFont(new Font("微软雅黑", Font.BOLD, 24));
|
|
|
|
|
mainPanel.add(titleLabel, BorderLayout.NORTH);
|
|
|
|
|
|
|
|
|
|
// Form panel - 增加用户名字段
|
|
|
|
|
JPanel formPanel = new JPanel(new GridLayout(8, 2, 10, 10));
|
|
|
|
|
// Form panel
|
|
|
|
|
JPanel formPanel = new JPanel(new GridLayout(6, 2, 10, 10));
|
|
|
|
|
|
|
|
|
|
JLabel usernameLabel = new JLabel("用户名:");
|
|
|
|
|
usernameLabel.setFont(new Font("微软雅黑", Font.PLAIN, 14));
|
|
|
|
|
@ -73,7 +80,7 @@ public class RegisterView extends JFrame {
|
|
|
|
|
formPanel.add(emailLabel);
|
|
|
|
|
formPanel.add(emailField);
|
|
|
|
|
formPanel.add(sendCodeButton);
|
|
|
|
|
formPanel.add(new JLabel());
|
|
|
|
|
formPanel.add(new JLabel()); // 空标签占位
|
|
|
|
|
formPanel.add(codeLabel);
|
|
|
|
|
formPanel.add(codeField);
|
|
|
|
|
formPanel.add(passwordLabel);
|
|
|
|
|
@ -81,17 +88,31 @@ public class RegisterView extends JFrame {
|
|
|
|
|
formPanel.add(confirmPasswordLabel);
|
|
|
|
|
formPanel.add(confirmPasswordField);
|
|
|
|
|
|
|
|
|
|
formPanel.add(registerButton);
|
|
|
|
|
|
|
|
|
|
mainPanel.add(formPanel, BorderLayout.CENTER);
|
|
|
|
|
|
|
|
|
|
// 创建底部面板,包含密码提示和返回按钮
|
|
|
|
|
JPanel bottomPanel = new JPanel(new BorderLayout(10, 10));
|
|
|
|
|
|
|
|
|
|
// 密码要求提示
|
|
|
|
|
JLabel hintLabel = new JLabel(
|
|
|
|
|
"<html><body style='text-align: center'>" +
|
|
|
|
|
"密码要求:6-10位,必须包含大小写字母和数字<br>" +
|
|
|
|
|
"例如:Abc123、Test456" +
|
|
|
|
|
"</body></html>", JLabel.CENTER);
|
|
|
|
|
hintLabel.setFont(new Font("微软雅黑", Font.PLAIN, 12));
|
|
|
|
|
hintLabel.setForeground(Color.GRAY);
|
|
|
|
|
bottomPanel.add(hintLabel, BorderLayout.CENTER);
|
|
|
|
|
|
|
|
|
|
// Back button
|
|
|
|
|
JButton backButton = new JButton("返回登录");
|
|
|
|
|
backButton.setFont(new Font("微软雅黑", Font.PLAIN, 14));
|
|
|
|
|
backButton.addActionListener(e -> NavigationController.showLoginView());
|
|
|
|
|
|
|
|
|
|
JPanel bottomPanel = new JPanel(new FlowLayout());
|
|
|
|
|
bottomPanel.add(backButton);
|
|
|
|
|
JPanel buttonPanel = new JPanel(new FlowLayout());
|
|
|
|
|
buttonPanel.add(registerButton); // 将注册按钮移到这里
|
|
|
|
|
buttonPanel.add(backButton);
|
|
|
|
|
bottomPanel.add(buttonPanel, BorderLayout.SOUTH);
|
|
|
|
|
|
|
|
|
|
mainPanel.add(bottomPanel, BorderLayout.SOUTH);
|
|
|
|
|
|
|
|
|
|
// Add action listeners
|
|
|
|
|
|