一、团队成员及任务
队长:
魏源 计科(智能)22-1 202203200006
负责模块:写一个用户GUI登录注册界面
队员:
葛海堂 计科(智能)22-1 202203200003
负责模块:游戏本体的逻辑设计和排行榜的录入
二、项目简介
本项目由我们二人合作完成,实现了登录注册的功能,可以进行账号注册并储存在文本文件中,猜数游戏也有相应的游戏提示,游戏结束后还会将成绩录入到排行榜中。
三、功能设计图
四、运行结果截图
五、核心源码
UserGUI.java
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class UserGUI implements ActionListener {
private static final String TITLE = "用户登录/注册界面";
private static final String LOGIN_PANEL = "登录";
private static final String REGISTER_PANEL = "注册";
private static final String CONFIRM = "确定";
private static final String CANCEL = "取消";
private static final String USER_DATA_FILE = "users.txt";
//存储用户数据的文件名
private JFrame frame;
//主窗口
private JTabbedPane tabbedPane;
//切换登录和注册的选项卡组件
private JPanel loginPanel;
//登录面板
private JPanel registerPanel;
//注册面板
private JTextField usernameField;
//用户名输入框
private JPasswordField passwordField;
//密码输入框
private JButton loginBtn;
//登录按钮
private JTextField newUsernameField;
//新用户名输入框(在注册面板中)
private JPasswordField newPasswordField;
//新密码输入框(在注册面板中)
private JPasswordField confirmPasswordField;
//确认新密码输入框(在注册面板中)
private JButton registerBtn;
//注册按钮
public UserGUI() {
frame = new JFrame(TITLE);
tabbedPane = new JTabbedPane();
loginPanel = createLoginPanel();
registerPanel = createRegisterPanel();
tabbedPane.addTab(LOGIN_PANEL, loginPanel);
tabbedPane.addTab(REGISTER_PANEL, registerPanel);
frame.add(tabbedPane);
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
private JPanel createLoginPanel() {
JPanel panel = new JPanel(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.gridx = 0;
c.gridy = 0;
c.anch