From 91d488fdb838334487c26aa129ae6fd0403eff24 Mon Sep 17 00:00:00 2001 From: Richard Schmidt Date: Tue, 6 Feb 2024 16:24:13 +0100 Subject: [PATCH] Added a file for a login GUI with basic GUI window --- .../java/{SignUp.java => CreateUser.java} | 19 +++++++------ src/main/java/SignUpGUI.java | 28 +++++++++++++++++++ user.json | 28 ++++++------------- 3 files changed, 46 insertions(+), 29 deletions(-) rename src/main/java/{SignUp.java => CreateUser.java} (83%) create mode 100644 src/main/java/SignUpGUI.java diff --git a/src/main/java/SignUp.java b/src/main/java/CreateUser.java similarity index 83% rename from src/main/java/SignUp.java rename to src/main/java/CreateUser.java index 964375b..8e8f15f 100644 --- a/src/main/java/SignUp.java +++ b/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 userList = readUserListFromJsonFile(filename); + List 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 readUserListFromJsonFile(String filename) { - List userList = new ArrayList<>(); + public static List readUserListFromJsonFile(String filename) { + List userList = new ArrayList<>(); try (Reader reader = new FileReader(filename)) { - Type userListType = new TypeToken>() {}.getType(); + Type userListType = new TypeToken>() {}.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()); diff --git a/src/main/java/SignUpGUI.java b/src/main/java/SignUpGUI.java new file mode 100644 index 0000000..ce58bc2 --- /dev/null +++ b/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); + }); + } +} \ No newline at end of file diff --git a/user.json b/user.json index 84627ce..7040154 100644 --- a/user.json +++ b/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" } ] \ No newline at end of file