commit f8634d7cea1d57a3958970f9d6c3a4642809d2c4 parent 3c0c7f83a26a6dd552d711b06ddb4fffd4671704 Author: William Lindholm <william_lindholm@outlook.com> Date: Wed, 27 Nov 2024 18:46:46 +0000 Now only updating games list if it has been changed Diffstat:
| M | TicTacToeClient/src/main/java/com/groupproject/tictactoeclient/ContentPanes/MainContentPanel.java | | | 11 | ++++++++++- |
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/TicTacToeClient/src/main/java/com/groupproject/tictactoeclient/ContentPanes/MainContentPanel.java b/TicTacToeClient/src/main/java/com/groupproject/tictactoeclient/ContentPanes/MainContentPanel.java @@ -17,6 +17,7 @@ public class MainContentPanel extends CustomPanel { private TicTacToeGrid grid; private JLabel gameStatusLabel; private JLabel currentGameLabel; + private String[] previousRawGames; public MainContentPanel(TicTacToeClient client) { @@ -213,6 +214,10 @@ public class MainContentPanel extends CustomPanel { openGamesList.setListData(new String[0]); } else { String[] rawGames = client.openGames.split("\n"); + + if (previousRawGames == null) { + previousRawGames = new String[0]; + } String[] formattedGames = new String[rawGames.length]; @@ -232,8 +237,12 @@ public class MainContentPanel extends CustomPanel { formattedGames[i] = " "; //set the box to nothing the format isnt right i.e if there is no host name } } + + if (rawGames.length != previousRawGames.length) { + openGamesList.setListData(formattedGames); + } + previousRawGames = rawGames; - openGamesList.setListData(formattedGames); //set userNameLabel as the current user logged in currentGameLabel.setText("Current Game : " + client.GID); }