commit 118748460e138d24af76032f48763f80d78e3670 parent c48ed3bf523c9e610f38598d50012f62252660ba Author: adglas21 <adamglasheen99@gmail.com> Date: Thu, 5 Dec 2024 11:56:50 +0000 Updated comments Diffstat:
3 files changed, 29 insertions(+), 16 deletions(-)
diff --git a/TicTacToeClient/src/main/java/com/groupproject/tictactoeclient/ContentPanes/MainContentPanel.java b/TicTacToeClient/src/main/java/com/groupproject/tictactoeclient/ContentPanes/MainContentPanel.java @@ -61,6 +61,7 @@ public class MainContentPanel extends CustomPanel { add(forfeitButton); add(logoutButton); + //create button constraint layout.putConstraint(SpringLayout.WEST, createGameButton, 20, SpringLayout.WEST, this); layout.putConstraint(SpringLayout.NORTH, createGameButton, 10, SpringLayout.NORTH, this); @@ -68,25 +69,30 @@ public class MainContentPanel extends CustomPanel { layout.putConstraint(SpringLayout.EAST, forfeitButton, -160, SpringLayout.EAST, grid); layout.putConstraint(SpringLayout.SOUTH, forfeitButton, -20, SpringLayout.SOUTH, this); + //leaderboard constraint layout.putConstraint(SpringLayout.WEST, allscoreButton, 20, SpringLayout.EAST, createGameButton); layout.putConstraint(SpringLayout.NORTH, allscoreButton, 0, SpringLayout.NORTH, createGameButton); + //Open games constraint layout.putConstraint(SpringLayout.WEST, openGamesScrollPane, 0, SpringLayout.WEST, createGameButton); layout.putConstraint(SpringLayout.EAST, openGamesScrollPane, 0, SpringLayout.EAST, allscoreButton); layout.putConstraint(SpringLayout.NORTH, openGamesScrollPane, 10, SpringLayout.SOUTH, createGameButton); layout.putConstraint(SpringLayout.SOUTH, openGamesScrollPane, -10, SpringLayout.NORTH, joinGameButton); + //Join game button constraint layout.putConstraint(SpringLayout.WEST, joinGameButton, 20, SpringLayout.WEST, this); layout.putConstraint(SpringLayout.SOUTH, joinGameButton, -20, SpringLayout.SOUTH, this); layout.putConstraint(SpringLayout.EAST, joinGameButton, 0, SpringLayout.EAST, allscoreButton); + //game status label constraint layout.putConstraint(SpringLayout.WEST, gameStatusLabel, 0, SpringLayout.WEST, grid); layout.putConstraint(SpringLayout.NORTH, gameStatusLabel, -20, SpringLayout.NORTH, grid); - //Username label + //current game label constraint layout.putConstraint(SpringLayout.WEST, currentGameLabel, 0, SpringLayout.WEST, grid); layout.putConstraint(SpringLayout.NORTH, currentGameLabel, -35, SpringLayout.NORTH, grid); + //game timer label constraints layout.putConstraint(SpringLayout.EAST, gameTimerLabel, 0, SpringLayout.EAST, grid); layout.putConstraint(SpringLayout.NORTH, gameTimerLabel, -20, SpringLayout.NORTH, grid); @@ -95,12 +101,15 @@ public class MainContentPanel extends CustomPanel { layout.putConstraint(SpringLayout.SOUTH, grid, 240, SpringLayout.NORTH, this); layout.putConstraint(SpringLayout.EAST, grid, -20, SpringLayout.EAST, this); + //logout button constraint layout.putConstraint(SpringLayout.SOUTH, logoutButton, -80, SpringLayout.SOUTH, this); layout.putConstraint(SpringLayout.EAST, logoutButton, -20, SpringLayout.EAST, this); + //score button constraint layout.putConstraint(SpringLayout.SOUTH, scoreButton, -20, SpringLayout.SOUTH, this); layout.putConstraint(SpringLayout.EAST, scoreButton, -20, SpringLayout.EAST, this); + openGamesList.addListSelectionListener(e -> { if (!e.getValueIsAdjusting() && openGamesList.getSelectedValue() != null) { String selectedGame = openGamesList.getSelectedValue(); @@ -277,7 +286,7 @@ public class MainContentPanel extends CustomPanel { //commented out as longer duration remainingTime = 15 * 60; - // Create a timer that updates every second + // timer that updates every second timer = new Timer(1000,new ActionListener() { @Override public void actionPerformed(ActionEvent e) { diff --git a/TicTacToeClient/src/main/java/com/groupproject/tictactoeclient/ContentPanes/register.java b/TicTacToeClient/src/main/java/com/groupproject/tictactoeclient/ContentPanes/register.java @@ -52,7 +52,7 @@ public class register extends CustomPanel { //Create a checkbox to show the password JCheckBox showPassword = new JCheckBox("show password"); - //Create error message if login is not correct + //Create error message if register is not correct JLabel registerErrorLabel = new JLabel("User is already created"); registerErrorLabel.setForeground(Color.red); registerErrorLabel.setVisible(false); @@ -136,19 +136,28 @@ public class register extends CustomPanel { JOptionPane.showMessageDialog(client.frame, "Please fill in all fields"); return; } + // stores the UID in responce and stores it as a global variable String response = client.proxy.register(usernameTextField.getText(), passwordTextField.getText(), nameTextField.getText(), surnameTextField.getText()); System.out.println(response); + //check if the username already exists, if not allow user to register if ("ERROR-REPEAT".equals(response)) { JOptionPane.showMessageDialog(client.frame, "User already exists"); return; } else { + + //register the user and assign a User id to the client client.UID = response; - client.username = usernameTextField.getText();// stores the username as a global + //stores the username + client.username = usernameTextField.getText(); + + + System.out.println("Client.UID = " + client.UID); + //once registered move to the main panel client.showPanel(new MainContentPanel(client)); } } @@ -157,19 +166,18 @@ public class register extends CustomPanel { //Item listener to check if the showPassword checkbox has been selected //If selected show the password and if not display the password as **** normal - char defaultPassword = passwordTextField.getEchoChar(); - // Login Button Action - check the entries of the textFields + char userPassword = passwordTextField.getEchoChar(); showPassword.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { passwordTextField.setEchoChar((char) 0); } else { - passwordTextField.setEchoChar(defaultPassword); + passwordTextField.setEchoChar(userPassword); } } }); - // Back button listener + // Back button listener - go back to the start panel backButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { diff --git a/TicTacToeClient/src/main/java/com/groupproject/tictactoeclient/HelperMethods.java b/TicTacToeClient/src/main/java/com/groupproject/tictactoeclient/HelperMethods.java @@ -73,10 +73,8 @@ public class HelperMethods { public void showOptions() { String[] options = {"Main Menu", "Quit"}; - - // Display an option dialog with custom options - // The user's choice is stored in the 'choice' - // variable + // Display an option dialog + // The user's choice is stored in the 'choice' variable int choice = JOptionPane.showOptionDialog( null, // Parent component (null means center on screen) "Options", // Message to display @@ -88,8 +86,7 @@ public class HelperMethods { options[0] // Initial selection (default is "Cancel") ); - // Check the user's choice and display a - // corresponding message + // Check the user's choice and display a corresponding message if (choice == JOptionPane.YES_OPTION) { // If the user chose 'Yes' // reset their game and put them back to the main menu @@ -98,8 +95,7 @@ public class HelperMethods { } else if (choice == JOptionPane.NO_OPTION) { // If the user chose 'No' - // quit the application - + // quit the application System.exit(0); } else {