Browse Source

Added a file for a login GUI with basic GUI window

remotes/origin/feature/client/make-input-field-buttons-interactive
Richard Schmidt 11 months ago
parent
commit
91d488fdb8
  1. 19
      src/main/java/CreateUser.java
  2. 28
      src/main/java/SignUpGUI.java
  3. 28
      user.json

19
src/main/java/SignUp.java → src/main/java/CreateUser.java

@ -12,14 +12,15 @@ import java.io.IOException;
import java.util.UUID;
class SignUp {
class CreateUser {
private String id;
private String userName;
private String password;
private String birthday;
// Constructor
public SignUp(String id, String name, String password, String birthday) {
public CreateUser(String id, String name, String password, String birthday) {
this.id = id;
this.userName = name;
this.password = password;
@ -60,7 +61,7 @@ class SignUp {
}
// Function to create user with validation
public static SignUp createUser(String id, String userName, String password, String birthday) {
public static CreateUser createUser(String id, String userName, String password, String birthday) {
if (userName == null || userName.isEmpty()) {
throw new IllegalArgumentException("Username cannot be empty");
}
@ -69,12 +70,12 @@ class SignUp {
}
if (password.length() < 6) {
throw new IllegalArgumentException("Password must be at least 6 characters long");
} return new SignUp(id, userName, password, birthday);
} return new CreateUser(id, userName, password, birthday);
}
// Function to save to JSON file, replace with database call later
public void saveToJsonFile(String filename) {
List<SignUp> userList = readUserListFromJsonFile(filename);
List<CreateUser> userList = readUserListFromJsonFile(filename);
userList.add(this);
try (FileWriter fileWriter = new FileWriter(filename)) {
@ -87,10 +88,10 @@ class SignUp {
}
// Function to read user information from a JSON file
public static List<SignUp> readUserListFromJsonFile(String filename) {
List<SignUp> userList = new ArrayList<>();
public static List<CreateUser> readUserListFromJsonFile(String filename) {
List<CreateUser> userList = new ArrayList<>();
try (Reader reader = new FileReader(filename)) {
Type userListType = new TypeToken<List<SignUp>>() {}.getType();
Type userListType = new TypeToken<List<CreateUser>>() {}.getType();
Gson gson = new Gson();
userList = gson.fromJson(reader, userListType);
} catch (FileNotFoundException e) {
@ -105,7 +106,7 @@ class SignUp {
try {
// Example usage
UUID randomUUID = UUID.randomUUID();
SignUp user = createUser(randomUUID.toString(), "Another Test User", "TestPasswort123", "01.01.2000");
CreateUser user = createUser(randomUUID.toString(), "Another Test User", "TestPasswort123", "01.01.2000");
// Example of accessing properties
System.out.println("UserID: " + user.getId());

28
src/main/java/SignUpGUI.java

@ -0,0 +1,28 @@
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.UUID;
public class SignUpGUI extends JFrame implements ActionListener {
public SignUpGUI() {
setTitle("Sign Up");
setSize(300, 200);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLayout(null);
}
@Override
public void actionPerformed(ActionEvent e) {
}
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
SignUpGUI signUpGUI = new SignUpGUI();
signUpGUI.setVisible(true);
});
}
}

28
user.json

@ -1,26 +1,14 @@
[
{
"id": "48728bbb-b924-48ce-aac0-3e38d6c7878e",
"userName": "Test User",
"password": "TestPasswort",
"birthday": "01.01.1900"
},
{
"id": "bacd2bf9-9486-4cc3-92fe-9a24b5cf47a4",
"userName": "Test User",
"password": "TestPasswort",
"birthday": "01.01.1900"
},
{
"id": "15474da8-c2cd-4c1c-ba57-cd1b8657140e",
"userName": "Test User",
"password": "TestPasswort",
"birthday": "01.01.1900"
"id": "f9cd70c1-57cd-4943-a00b-0de521347aff",
"userName": "asd",
"password": "test1234",
"birthday": "01.01.2000"
},
{
"id": "be83e49a-bb17-4be2-a50f-0b846d7de3ea",
"userName": "Another Test User",
"password": "TestPasswort123",
"birthday": "01.01.2000"
"id": "69e4b1d3-3089-4f98-936f-865dfe40e6a0",
"userName": "asd",
"password": "test1234",
"birthday": "01.01.2013"
}
]
Loading…
Cancel
Save