From 3153f7027d74b15052058441962c713a6c309af6 Mon Sep 17 00:00:00 2001 From: Jona Walpert Date: Thu, 2 Apr 2026 18:50:20 +0200 Subject: [PATCH] fix: temporyy fix for NPE and wrong naming --- .../client/ui/chatui/ChatViewController.java | 58 +++++++++++++------ .../ui-structure/components/Chatbox.fxml | 2 +- 2 files changed, 40 insertions(+), 20 deletions(-) diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/chatui/ChatViewController.java b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/chatui/ChatViewController.java index 607204d..740f6ef 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/chatui/ChatViewController.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/chatui/ChatViewController.java @@ -23,20 +23,28 @@ public class ChatViewController { private final ChatController controller; private final Timer timer; - @FXML private VBox chatVBox; + @FXML + private VBox chatVBox; - @FXML private TextField inputField; + @FXML + private TextField inputField; - @FXML private ScrollPane chatScrollPane; + @FXML + private ScrollPane chatScrollPane; - @FXML private Button sendButton; + @FXML + private Button sendButton; - @FXML private Button refreshButton; + @FXML + private Button refreshButton; private static final int CHAT_PADDING = 20; public ChatViewController() { - this(null, null ,null); + this.username = null; + this.chatmodel = null; + this.controller = null; + this.timer = new Timer(); } public ChatViewController(String username, ChatModel chatmodel, ChatController controller) { @@ -44,23 +52,33 @@ public class ChatViewController { this.chatmodel = chatmodel; this.controller = controller; this.timer = new Timer(); - timer.schedule(new TimerTask() { - @Override - public void run() { - System.err.println("tick"); - if (controller.receiveMessage()) { - showMessage(); + if (this.controller != null) { + timer.schedule(new TimerTask() { + @Override + public void run() { + System.err.println("tick"); + if (ChatViewController.this.controller.receiveMessage()) { + showMessage(); + } } - } - }, 0, 1000); + }, 0, 1000); + } } @FXML public void initialize() { - inputField.setOnAction(event -> sendMessage()); - sendButton.setOnAction(event -> sendMessage()); - refreshButton.setOnAction(event -> showMessage()); - chatScrollPane.vvalueProperty().bind(chatVBox.heightProperty()); + if (inputField != null) { + inputField.setOnAction(event -> sendMessage()); + } + if (sendButton != null) { + sendButton.setOnAction(event -> sendMessage()); + } + if (refreshButton != null) { + refreshButton.setOnAction(event -> showMessage()); + } + if (chatScrollPane != null && chatVBox != null) { + chatScrollPane.vvalueProperty().bind(chatVBox.heightProperty()); + } } public void showMessage() { @@ -83,5 +101,7 @@ public class ChatViewController { } } - public void endController() { timer.cancel(); } + public void endController() { + timer.cancel(); + } } diff --git a/src/main/resources/ui-structure/components/Chatbox.fxml b/src/main/resources/ui-structure/components/Chatbox.fxml index c61e28e..6fdfad6 100644 --- a/src/main/resources/ui-structure/components/Chatbox.fxml +++ b/src/main/resources/ui-structure/components/Chatbox.fxml @@ -19,7 +19,7 @@