fixed Issue #28 by checking if username contains space before starting connection

This commit is contained in:
Andrin Fassbind 2022-04-14 19:33:18 +02:00
parent b47d98b960
commit b6fd5b569d
1 changed files with 14 additions and 10 deletions

View File

@ -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() {