1
+ import junit .framework .JUnit4TestAdapter ;
2
+
1
3
import javax .swing .*;
4
+ import java .awt .event .ActionEvent ;
5
+ import java .awt .event .ActionListener ;
6
+ import java .io .File ;
2
7
3
- public class UserRegistrationUI implements UserRegistrationUseCase {
8
+ public class UserRegistrationUI implements UserRegistrationUseCase , ActionListener {
4
9
private UserDatabase database ;
5
10
6
- public UserRegistrationUI (UserDatabase database ){
11
+ //Front end related objects
12
+ private JFrame RegisterFrame ;
13
+ private JPanel RegisterPanel ;
14
+ private JLabel usernameLabel ;
15
+ private JLabel passwordLabel ;
16
+ private JLabel emailLabel ;
17
+ private JTextField usernameText ;
18
+ private JTextField passwordText ;
19
+ private JTextField emailText ;
20
+ private JButton register ;
21
+
22
+ public UserRegistrationUI (UserDatabase database ) {
7
23
this .database = database ;
8
24
}
9
25
void GetUserCredentials (){
10
- JFrame RegisterFrame = new JFrame ();
11
- RegisterFrame .setSize (1000 , 1000 );
26
+ RegisterFrame = new JFrame ();
27
+ RegisterFrame .setSize (300 , 300 );
12
28
RegisterFrame .setDefaultCloseOperation (JFrame .EXIT_ON_CLOSE );
13
- JPanel RegisterPanel = new JPanel ();
29
+ RegisterPanel = new JPanel ();
14
30
RegisterFrame .add (RegisterPanel );
15
31
16
32
//The textbox for entering the Username
17
33
RegisterPanel .setLayout (null );
18
- JLabel usernameLabel = new JLabel ("Username" );
34
+ usernameLabel = new JLabel ("Username" );
19
35
usernameLabel .setBounds (10 , 25 , 100 , 25 );
36
+ RegisterPanel .add (usernameLabel );
20
37
21
- JTextField usernameText = new JTextField (20 );
38
+ usernameText = new JTextField (20 );
22
39
usernameText .setBounds (100 , 20 , 165 , 25 );
23
40
RegisterPanel .add (usernameText );
24
41
25
42
//The textbox for entering the password
26
- JPasswordField passwordText = new JPasswordField ();
43
+ passwordLabel = new JLabel ("Password" );
44
+ passwordLabel .setBounds (10 , 55 , 100 , 25 );
45
+ RegisterPanel .add (passwordLabel );
46
+
47
+ passwordText = new JPasswordField ();
27
48
passwordText .setBounds (100 , 50 , 165 , 25 );
28
49
RegisterPanel .add (passwordText );
29
50
30
51
//The textbox for entering the email
31
- JLabel
52
+ emailLabel = new JLabel ("Email" );
53
+ emailLabel .setBounds (10 , 85 , 100 , 25 );
54
+ RegisterPanel .add (emailLabel );
55
+
56
+ emailText = new JTextField (20 );
57
+ emailText .setBounds (100 , 80 , 165 , 25 );
58
+ RegisterPanel .add (emailText );
59
+
60
+ //The Button
61
+ register = new JButton ("Register" );
62
+ register .setBounds (100 , 110 , 165 , 25 );
63
+ RegisterPanel .add (register );
64
+
65
+
32
66
33
67
RegisterFrame .setVisible (true );
34
68
}
@@ -39,6 +73,8 @@ public void registerUser(String username, String password, String email) {
39
73
}else {
40
74
database .createUser (username , password , email , "Basic" );
41
75
System .out .println ("Your account has been created, please verify to login" );
76
+ UserVerificationUI verifyUser = new UserVerificationUI (389 );
77
+ verifyUser .verify (email );
42
78
}
43
79
}
44
80
@@ -47,4 +83,13 @@ public static void main(String[] args){
47
83
UserRegistrationUI testUI = new UserRegistrationUI (testDB );
48
84
testUI .GetUserCredentials ();
49
85
}
86
+
87
+ @ Override
88
+ public void actionPerformed (ActionEvent e ) {
89
+ String username = usernameText .getText ();
90
+ String password = passwordText .getText ();
91
+ String email = emailText .getText ();
92
+ this .registerUser (username , password , email );
93
+
94
+ }
50
95
}
0 commit comments