@Override
    public void actionPerformed(ActionEvent e) {
        /**
         * ActionListener for Start Button.  
         * 
         * Creates MainWindow and closes LoginWindow if username is valid.
         * Else, print an error.
         */
        if(e.getSource().equals(startButton)) {
            //check for valid inputs. 
            String newUser = usernameInput.getText();
            if (!portInput.getText().matches("[0-9]+")) {
                errorLabel.setText("Set valid port number.");
                return;
            }
            if (hostInput.getText().equals(null)) {
                errorLabel.setText("Set valid host.");
                return;
            }
            if (!usernameInput.getText().trim().matches("[a-zA-Z0-9]+")) {
                errorLabel.setText("Username must be alphanumeric characters.");
                return;
            }

            port = Integer.parseInt(portInput.getText()); 
            host = hostInput.getText();
            hostInput.setEditable(false);
            portInput.setEditable(false);
            usernameInput.setEditable(false);
            if (newUser.trim() != null) {
                client = new Client(host,port,newUser);
                try {
                    String result = client.startDialog();
                    if(!result.equals("Connected")) {
                        if (result.equals("Username already taken.")){
                            errorLabel.setText("Username is already taken.");
                            usernameInput.setEditable(true);
                        }
                        else {
                            errorLabel.setText("Error connecting to server.");
                            hostInput.setText("");
                            portInput.setText("");
                            hostInput.setEditable(true);
                            portInput.setEditable(true);
                            usernameInput.setEditable(true);
                        }
                    }

                    else if (client.username.equals(null)) {
                        errorLabel.setText("Username must be alphanumeric characters.");
                        usernameInput.setText("");
                        hostInput.setEditable(true);
                        portInput.setEditable(true);
                        usernameInput.setEditable(true);
                    }

                    else {
                        dispose();
                        startMainWindow(client);
                    }
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            }
            else {
                errorLabel.setText("Connection failed. Please try again!");
                usernameInput.setText("");
                hostInput.setEditable(true);
                portInput.setEditable(true);
                usernameInput.setEditable(true);
            }
        }   
    }