private void cmd_connectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmd_connectActionPerformed


        boolean connectionSuccessfull = false;
        try {
            connectionSuccessfull = cl.listenSocket(txt_username.getText(), cl.SHA(txt_password.getText()));
        } catch (Exception ex) {
            Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
        }

        try {
        if (connectionSuccessfull == true && txt_username.getText() != null && txt_password.getPassword() != null) {



            //write the current user in the tablist
            //userTabList.add(txt_username.getText());
            //userTabList.add("chat");
            //System.out.println(tabpanel_chathistory.getTitleAt(tabpanel_chathistory.getSelectedIndex()).toString());


            // userTabList.add("chat");
            //userTabList.add(tabpanel_chathistory.getTitleAt(tabpanel_chathistory.getSelectedIndex()));


            //enable elements needed for the chat
            cmd_disconnect.setEnabled(true);
            cmd_send.setEnabled(true);
            txt_sendingField.setEnabled(true);
            tabpanel_chathistory.setEnabled(true);
            lbx_users_online.setEnabled(true);
            txt_chatHistory.setEnabled(true);

            //disable not needed elements
            cmd_regNewUser.setEnabled(false);
            txt_username.setEnabled(false);
            txt_password.setEnabled(false);
            cmd_connect.setEnabled(false);


            try {
                System.out.println("in try, before readline");
                //handles initial sending from the server to client
                String history = "";
                history = cl.in.readUTF() + "\n";
                System.out.println("nach 1 readline");
                txt_chatHistory.setText(history);
                //txt_chatHistory.setText(history+cl.in.readUTF());
                System.out.println("nach 2 readline");

            } catch (IOException ex) {
                Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
            }

            Thread clientlistener = new ClientThread(cl.socket, txt_chatHistory, tabpanel_chathistory, txt_username.getText());
            clientlistener.start();
        } else {
            System.out.println("Connection could not be established");
        }
        } catch (Exception ex) {
            System.err.println("Username or Password can't be empty");
        }
    }//GEN-LAST:event_cmd_connectActionPerformed