From bc86c47871b2f229990ea8838a361348c781ec22 Mon Sep 17 00:00:00 2001 From: schrom01 Date: Fri, 15 Apr 2022 01:26:24 +0200 Subject: [PATCH] fixed Method Initializing. Setting Datafields serverAddress and serverPort. #24 --- .../pm2/multichat/client/ClientConnectionHandler.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/client/src/main/java/ch/zhaw/pm2/multichat/client/ClientConnectionHandler.java b/client/src/main/java/ch/zhaw/pm2/multichat/client/ClientConnectionHandler.java index 983c34c..e13af84 100644 --- a/client/src/main/java/ch/zhaw/pm2/multichat/client/ClientConnectionHandler.java +++ b/client/src/main/java/ch/zhaw/pm2/multichat/client/ClientConnectionHandler.java @@ -34,9 +34,16 @@ public class ClientConnectionHandler extends ConnectionHandler implements Runnab } public void initialize(String serverAddress, int serverPort, String userName) throws IOException { - state = new SimpleObjectProperty<>(NEW); - setConnection(NetworkHandler.openConnection(serverAddress, serverPort)); + this.state = new SimpleObjectProperty<>(NEW); + this.serverAddress = new SimpleStringProperty(serverAddress); + this.serverPort = new SimpleIntegerProperty(serverPort); this.userName = new SimpleStringProperty((userName == null || userName.isBlank())? USER_NONE : userName); + try { + setConnection(NetworkHandler.openConnection(this.serverAddress.get(), this.serverPort.get())); + } catch (IOException e) { + messages.addMessage(new Message(Message.MessageType.ERROR,null,null,e.getMessage())); + System.out.println("ERROR: " + e.getMessage()); + } } public SimpleStringProperty getServerAddressProperty() { return serverAddress; }