Skip to content

Commit

Permalink
删除RegisterDialog文件改为在Register中的内部类
Browse files Browse the repository at this point in the history
添加了注册时的输入检测
注册后显示用户名
  • Loading branch information
pluschen-stack committed Aug 11, 2020
1 parent 3746ee5 commit 11de6ae
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 26 deletions.
Binary file added out/production/ATM/Main.class
Binary file not shown.
Binary file removed out/production/ATM/auth/Main.class
Binary file not shown.
Binary file modified out/production/ATM/auth/Register$2.class
Binary file not shown.
Binary file not shown.
Binary file modified out/production/ATM/auth/Register.class
Binary file not shown.
Binary file removed out/production/ATM/auth/RegisterDialog.class
Binary file not shown.
10 changes: 5 additions & 5 deletions out/production/ATM/druid.properties
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
driverClassName=com.mysql.cj.jdbc.Driver
url=jdbc:mysql://localhost:3306/atm?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC
url=jdbc:mysql://localhost:3306/java_bank?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC
username=root
password=523698741qwer
# 初始化连接数量
password=123456123456
# ��ʼ����������
initialSize=15
# 最大连接数
# ���������
maxActive=30
# 最大等待时间
# ���ȴ�ʱ��
maxWait=3000
63 changes: 49 additions & 14 deletions src/auth/Register.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ public class Register extends JFrame {
private PreparedStatement preparedStatement = null;
private ResultSet resultset = null;

private int loginWidth = 400;
private int loginHeight = 400;
private int RegisterWidth = 400;
private int RegisterHeight = 400;
private int x = 600;
private int y = 250;

Random random = new Random(System.currentTimeMillis());

public Register() {
setBounds(x, y, loginWidth, loginHeight);
setBounds(x, y, RegisterWidth, RegisterHeight);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setResizable(false);
setTitle("Java大作业银行注册界面");
Expand All @@ -39,6 +39,10 @@ public Register() {
userNameField.setBounds(100, 50, 200, 50);
contentPane.add(userNameField);

JLabel userNameNotice = new JLabel("长度:(0,10]");
userNameNotice.setBounds(300, 50, 200, 50);
contentPane.add(userNameNotice);

JLabel userPasswordLable = new JLabel("密码");
userPasswordLable.setBounds(50, 100, 50, 50);
contentPane.add(userPasswordLable);
Expand All @@ -47,6 +51,10 @@ public Register() {
passwordField1.setBounds(100, 100, 200, 50);
contentPane.add(passwordField1);

JLabel userPasswordNotice = new JLabel("长度:[10,18]");
userPasswordNotice.setBounds(300, 100, 200, 50);
contentPane.add(userPasswordNotice);

JLabel userPasswordLable2 = new JLabel("确认密码");
userPasswordLable2.setBounds(50, 150, 50, 50);
contentPane.add(userPasswordLable2);
Expand Down Expand Up @@ -79,37 +87,38 @@ public void actionPerformed(ActionEvent e) {
String userPassword2 = passwordField2.getText();
int userID = random.nextInt(1000000000) + 1000000000;//生成十亿到二十亿的随机数,用来当作用户id
Boolean flag = true;
try{
try {
connection = DButil.getConnection();
String sql = "select user_id from t_user where user_id = ?";
preparedStatement = connection.prepareStatement(sql);
preparedStatement.setInt(1,userID);
preparedStatement.setInt(1, userID);

resultset = preparedStatement.executeQuery();
if(resultset.next()){
if (resultset.next()) {
flag = !flag;
}
} catch (SQLException throwables) {
throwables.printStackTrace();
}finally {
} finally {
DButil.close(connection, preparedStatement, resultset);
}
System.out.println(userID);

if (userPassword1.equals(userPassword2) && userName.length() <= 10 &&flag) {
if (userPassword1.equals(userPassword2) && userName.length() <= 10 && userName.length() >= 0 && flag && userPassword2.length() >= 10 && userPassword2.length() <= 18) {
String sql = "insert into t_user (user_id,user_name,user_password) values (?,?,?)";
try{
try {
connection = DButil.getConnection();
preparedStatement = connection.prepareStatement(sql);
preparedStatement.setInt(1,userID);
preparedStatement.setString(2,userName);
preparedStatement.setInt(1, userID);
preparedStatement.setString(2, userName);
String userPassword = MD5.executeMD5(userPassword1);
preparedStatement.setString(3,userPassword);
preparedStatement.setString(3, userPassword);

new RegisterDialog(userID);
preparedStatement.execute();
}catch (SQLException | NoSuchAlgorithmException throwables){
} catch (SQLException | NoSuchAlgorithmException throwables) {
throwables.printStackTrace();
}finally {
} finally {
DButil.close(connection, preparedStatement, resultset);
}
}
Expand All @@ -121,4 +130,30 @@ public void actionPerformed(ActionEvent e) {
public static void main(String[] args) {
new Register();
}


class RegisterDialog extends JDialog {
public RegisterDialog(long userID) {
setBounds(x + 100, y + 100, 200, 200);
setTitle("java大作业银行");
Container contentPane = getContentPane();
contentPane.setLayout(null);

JButton jButton = new JButton("确认");
jButton.setBounds(50, 125, 100, 25);
JLabel jLabel = new JLabel("你的账户是" + String.valueOf(userID));
jLabel.setBounds(25, 50, 150, 25);

jButton.addActionListener(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
dispose();
}
});
contentPane.add(jLabel);
contentPane.add(jButton);

setVisible(true);
}
}
}
7 changes: 0 additions & 7 deletions src/auth/RegisterDialog.java

This file was deleted.

0 comments on commit 11de6ae

Please sign in to comment.