Browse Source

added functionality to the textfields, the input is now written to the user.json file

remotes/origin/feature/client/make-input-field-buttons-interactive
Richard Schmidt 11 months ago
parent
commit
583188ac5a
  1. 20
      src/main/java/SignUpGUI.java
  2. 6
      user.json

20
src/main/java/SignUpGUI.java

@ -5,6 +5,7 @@ import java.util.UUID;
public class SignUpGUI extends JFrame implements ActionListener { public class SignUpGUI extends JFrame implements ActionListener {
private JTextField usernameField, passwordField, birthdayField; private JTextField usernameField, passwordField, birthdayField;
private JButton signUpButton;
public SignUpGUI() { public SignUpGUI() {
setTitle("Sign Up"); setTitle("Sign Up");
@ -36,10 +37,29 @@ public class SignUpGUI extends JFrame implements ActionListener {
birthdayField.setBounds(100, 80, 160, 25); birthdayField.setBounds(100, 80, 160, 25);
add(birthdayField); add(birthdayField);
signUpButton = new JButton("Sign Up");
signUpButton.setBounds(100, 120, 100, 25);
signUpButton.addActionListener(this);
add(signUpButton);
} }
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
if (e.getSource() == signUpButton) {
String username = usernameField.getText();
String password = passwordField.getText();
String birthday = birthdayField.getText();
try {
UUID randomUUID = UUID.randomUUID();
CreateUser user = CreateUser.createUser(randomUUID.toString(), username, password, birthday);
user.saveToJsonFile("user.json");
JOptionPane.showMessageDialog(this, "User signed up successfully!");
} catch (IllegalArgumentException ex) {
JOptionPane.showMessageDialog(this, "Error: " + ex.getMessage(), "Sign Up Error", JOptionPane.ERROR_MESSAGE);
}
}
} }
public static void main(String[] args) { public static void main(String[] args) {

6
user.json

@ -10,5 +10,11 @@
"userName": "asd", "userName": "asd",
"password": "test1234", "password": "test1234",
"birthday": "01.01.2013" "birthday": "01.01.2013"
},
{
"id": "4165bfe6-9851-480f-90e1-8229415fa44e",
"userName": "asdasdasd",
"password": "1231412512",
"birthday": "1111111"
} }
] ]
Loading…
Cancel
Save