fix: temporyy fix for NPE and wrong naming

This commit is contained in:
Jona Walpert
2026-04-02 18:50:20 +02:00
parent b5d19d915b
commit 3153f7027d
2 changed files with 40 additions and 20 deletions
@@ -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,24 +52,34 @@ public class ChatViewController {
this.chatmodel = chatmodel;
this.controller = controller;
this.timer = new Timer();
if (this.controller != null) {
timer.schedule(new TimerTask() {
@Override
public void run() {
System.err.println("tick");
if (controller.receiveMessage()) {
if (ChatViewController.this.controller.receiveMessage()) {
showMessage();
}
}
}, 0, 1000);
}
}
@FXML
public void initialize() {
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() {
while (chatmodel.count > 0) {
@@ -83,5 +101,7 @@ public class ChatViewController {
}
}
public void endController() { timer.cancel(); }
public void endController() {
timer.cancel();
}
}
@@ -19,7 +19,7 @@
<VBox xmlns="http://javafx.com/javafx/21"
xmlns:fx="http://javafx.com/fxml/1"
fx:controller="ch.unibas.dmi.dbis.cs108.casono.client.ui.chatui.ChatController"
fx:controller="ch.unibas.dmi.dbis.cs108.casono.client.ui.chatui.ChatViewController"
alignment="CENTER"
stylesheets="@Chatui.css">