|
@ -5,12 +5,12 @@ import java.util.List; |
|
|
import java.util.UUID; |
|
|
import java.util.UUID; |
|
|
|
|
|
|
|
|
public class SignUpGUI extends JFrame implements ActionListener { |
|
|
public class SignUpGUI extends JFrame implements ActionListener { |
|
|
private JTextField usernameField, passwordField, confirmPasswordField, birthdayField; |
|
|
|
|
|
|
|
|
private JTextField usernameField, passwordField, confirmPasswordField, birthdayField, firstNameField, surnameField; |
|
|
private JButton signUpButton; |
|
|
private JButton signUpButton; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public SignUpGUI() { |
|
|
public SignUpGUI() { |
|
|
setTitle("Sign Up"); |
|
|
setTitle("Sign Up"); |
|
|
setSize(300, 250); |
|
|
|
|
|
|
|
|
setSize(400, 300); // Adjusted size for accommodating more fields |
|
|
setDefaultCloseOperation(EXIT_ON_CLOSE); |
|
|
setDefaultCloseOperation(EXIT_ON_CLOSE); |
|
|
setLayout(null); |
|
|
setLayout(null); |
|
|
|
|
|
|
|
@ -19,7 +19,7 @@ public class SignUpGUI extends JFrame implements ActionListener { |
|
|
add(usernameLabel); |
|
|
add(usernameLabel); |
|
|
|
|
|
|
|
|
usernameField = new JTextField(); |
|
|
usernameField = new JTextField(); |
|
|
usernameField.setBounds(100, 20, 160, 25); |
|
|
|
|
|
|
|
|
usernameField.setBounds(140, 20, 160, 25); |
|
|
add(usernameField); |
|
|
add(usernameField); |
|
|
|
|
|
|
|
|
JLabel passwordLabel = new JLabel("Password:"); |
|
|
JLabel passwordLabel = new JLabel("Password:"); |
|
@ -27,7 +27,7 @@ public class SignUpGUI extends JFrame implements ActionListener { |
|
|
add(passwordLabel); |
|
|
add(passwordLabel); |
|
|
|
|
|
|
|
|
passwordField = new JPasswordField(); |
|
|
passwordField = new JPasswordField(); |
|
|
passwordField.setBounds(100, 50, 160, 25); |
|
|
|
|
|
|
|
|
passwordField.setBounds(140, 50, 160, 25); |
|
|
add(passwordField); |
|
|
add(passwordField); |
|
|
|
|
|
|
|
|
JLabel confirmPasswordLabel = new JLabel("Confirm Password:"); |
|
|
JLabel confirmPasswordLabel = new JLabel("Confirm Password:"); |
|
@ -35,22 +35,37 @@ public class SignUpGUI extends JFrame implements ActionListener { |
|
|
add(confirmPasswordLabel); |
|
|
add(confirmPasswordLabel); |
|
|
|
|
|
|
|
|
confirmPasswordField = new JPasswordField(); |
|
|
confirmPasswordField = new JPasswordField(); |
|
|
confirmPasswordField.setBounds(140, 80, 120, 25); |
|
|
|
|
|
|
|
|
confirmPasswordField.setBounds(140, 80, 160, 25); |
|
|
add(confirmPasswordField); |
|
|
add(confirmPasswordField); |
|
|
|
|
|
|
|
|
|
|
|
JLabel firstNameLabel = new JLabel("First Name:"); // New field for first name |
|
|
|
|
|
firstNameLabel.setBounds(20, 110, 80, 25); |
|
|
|
|
|
add(firstNameLabel); |
|
|
|
|
|
|
|
|
|
|
|
firstNameField = new JTextField(); |
|
|
|
|
|
firstNameField.setBounds(140, 110, 160, 25); |
|
|
|
|
|
add(firstNameField); |
|
|
|
|
|
|
|
|
|
|
|
JLabel surnameLabel = new JLabel("Surname:"); // New field for surname |
|
|
|
|
|
surnameLabel.setBounds(20, 140, 80, 25); |
|
|
|
|
|
add(surnameLabel); |
|
|
|
|
|
|
|
|
|
|
|
surnameField = new JTextField(); |
|
|
|
|
|
surnameField.setBounds(140, 140, 160, 25); |
|
|
|
|
|
add(surnameField); |
|
|
|
|
|
|
|
|
JLabel birthdayLabel = new JLabel("Birthday:"); |
|
|
JLabel birthdayLabel = new JLabel("Birthday:"); |
|
|
birthdayLabel.setBounds(20, 110, 80, 25); |
|
|
|
|
|
|
|
|
birthdayLabel.setBounds(20, 170, 80, 25); |
|
|
add(birthdayLabel); |
|
|
add(birthdayLabel); |
|
|
|
|
|
|
|
|
birthdayField = new JTextField(); |
|
|
birthdayField = new JTextField(); |
|
|
birthdayField.setBounds(100, 110, 160, 25); |
|
|
|
|
|
|
|
|
birthdayField.setBounds(140, 170, 160, 25); |
|
|
add(birthdayField); |
|
|
add(birthdayField); |
|
|
|
|
|
|
|
|
signUpButton = new JButton("Sign Up"); |
|
|
signUpButton = new JButton("Sign Up"); |
|
|
signUpButton.setBounds(100, 150, 100, 25); |
|
|
|
|
|
|
|
|
signUpButton.setBounds(140, 210, 100, 25); // Adjusted position |
|
|
signUpButton.addActionListener(this); |
|
|
signUpButton.addActionListener(this); |
|
|
add(signUpButton); |
|
|
add(signUpButton); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
@ -60,6 +75,8 @@ public class SignUpGUI extends JFrame implements ActionListener { |
|
|
String password = passwordField.getText(); |
|
|
String password = passwordField.getText(); |
|
|
String confirmPassword = confirmPasswordField.getText(); |
|
|
String confirmPassword = confirmPasswordField.getText(); |
|
|
String birthday = birthdayField.getText(); |
|
|
String birthday = birthdayField.getText(); |
|
|
|
|
|
String firstName = firstNameField.getText(); |
|
|
|
|
|
String surname = surnameField.getText(); |
|
|
|
|
|
|
|
|
if (!password.equals(confirmPassword)) { |
|
|
if (!password.equals(confirmPassword)) { |
|
|
JOptionPane.showMessageDialog(this, "Passwords do not match!", "Sign Up Error", JOptionPane.ERROR_MESSAGE); |
|
|
JOptionPane.showMessageDialog(this, "Passwords do not match!", "Sign Up Error", JOptionPane.ERROR_MESSAGE); |
|
@ -72,7 +89,7 @@ public class SignUpGUI extends JFrame implements ActionListener { |
|
|
} |
|
|
} |
|
|
try { |
|
|
try { |
|
|
UUID randomUUID = UUID.randomUUID(); |
|
|
UUID randomUUID = UUID.randomUUID(); |
|
|
CreateUser user = CreateUser.createUser(randomUUID.toString(), username, password, birthday); |
|
|
|
|
|
|
|
|
CreateUser user = CreateUser.createUser(randomUUID.toString(), username, password, birthday, firstName, surname); |
|
|
user.saveToJsonFile("user.json"); |
|
|
user.saveToJsonFile("user.json"); |
|
|
JOptionPane.showMessageDialog(this, "User signed up successfully!"); |
|
|
JOptionPane.showMessageDialog(this, "User signed up successfully!"); |
|
|
dispose(); |
|
|
dispose(); |
|
|