fix: temporyy fix for NPE and wrong naming
This commit is contained in:
+39
-19
@@ -23,20 +23,28 @@ public class ChatViewController {
|
|||||||
private final ChatController controller;
|
private final ChatController controller;
|
||||||
private final Timer timer;
|
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;
|
private static final int CHAT_PADDING = 20;
|
||||||
|
|
||||||
public ChatViewController() {
|
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) {
|
public ChatViewController(String username, ChatModel chatmodel, ChatController controller) {
|
||||||
@@ -44,23 +52,33 @@ public class ChatViewController {
|
|||||||
this.chatmodel = chatmodel;
|
this.chatmodel = chatmodel;
|
||||||
this.controller = controller;
|
this.controller = controller;
|
||||||
this.timer = new Timer();
|
this.timer = new Timer();
|
||||||
timer.schedule(new TimerTask() {
|
if (this.controller != null) {
|
||||||
@Override
|
timer.schedule(new TimerTask() {
|
||||||
public void run() {
|
@Override
|
||||||
System.err.println("tick");
|
public void run() {
|
||||||
if (controller.receiveMessage()) {
|
System.err.println("tick");
|
||||||
showMessage();
|
if (ChatViewController.this.controller.receiveMessage()) {
|
||||||
|
showMessage();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}, 0, 1000);
|
||||||
}, 0, 1000);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
inputField.setOnAction(event -> sendMessage());
|
if (inputField != null) {
|
||||||
sendButton.setOnAction(event -> sendMessage());
|
inputField.setOnAction(event -> sendMessage());
|
||||||
refreshButton.setOnAction(event -> showMessage());
|
}
|
||||||
chatScrollPane.vvalueProperty().bind(chatVBox.heightProperty());
|
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() {
|
public void showMessage() {
|
||||||
@@ -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"
|
<VBox xmlns="http://javafx.com/javafx/21"
|
||||||
xmlns:fx="http://javafx.com/fxml/1"
|
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"
|
alignment="CENTER"
|
||||||
stylesheets="@Chatui.css">
|
stylesheets="@Chatui.css">
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user