diff --git a/client/src/main/java/ch/zhaw/pm2/multichat/client/ChatWindowController.java b/client/src/main/java/ch/zhaw/pm2/multichat/client/ChatWindowController.java index 1a8a9c6..c657f44 100644 --- a/client/src/main/java/ch/zhaw/pm2/multichat/client/ChatWindowController.java +++ b/client/src/main/java/ch/zhaw/pm2/multichat/client/ChatWindowController.java @@ -106,18 +106,22 @@ public class ChatWindowController { private void startConnectionHandler() throws IOException { String userName = userNameField.getText(); - String serverAddress = serverAddressField.getText(); - int serverPort = Integer.parseInt(serverPortField.getText()); - connectionHandler = new ClientConnectionHandler( - NetworkHandler.openConnection(serverAddress, serverPort), userName, - messages); - new Thread(connectionHandler).start(); + if(!userName.contains(" ")) { + String serverAddress = serverAddressField.getText(); + int serverPort = Integer.parseInt(serverPortField.getText()); + connectionHandler = new ClientConnectionHandler( + NetworkHandler.openConnection(serverAddress, serverPort), userName, + messages); + new Thread(connectionHandler).start(); - //register Listener - startListener(); + //register Listener + startListener(); - // register window close handler - rootPane.getScene().getWindow().addEventHandler(WindowEvent.WINDOW_CLOSE_REQUEST, windowCloseHandler); + // register window close handler + rootPane.getScene().getWindow().addEventHandler(WindowEvent.WINDOW_CLOSE_REQUEST, windowCloseHandler); + } else { + addError("It is not allowed to have spaces in username!"); + } } private void terminateConnectionHandler() {