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

        String message;
        String action;
        String tabtitle = tabpanel_chathistory.getTitleAt(tabpanel_chathistory.getSelectedIndex()).toString();
        System.out.println("current tab title: " + tabtitle);
        
        message = "[" + txt_sendingField.getText() + "]";
        if(tabtitle.equals("Chat"))
            action = "[BROADCAST]";
        else if (tabtitle.contains(","))
            action = "[USERS]";
        else
            action = "[USER]";
         
        tabtitle = "[" + tabtitle + "]";
        
        //checks if sending field is empty
        if (!"".equals(txt_sendingField.getText())) {
            try {
                //write message to outputstream
                cl.out.writeUTF(action + tabtitle + message);
                cl.out.flush();
                System.out.println("OUTCOMMING: " + action + tabtitle + message);
                System.out.println("message for: " + tabtitle + " content: " + message);
                
                
                JTabbedPane panel = tabpanel_chathistory;
                int i = panel.getSelectedIndex();
                System.out.println(i);
                //System.out.println("selected component: "+panel.getComponentAt(i).toString());
                

                
                if(i !=0){
                    JTextArea currentTabHistory = (JTextArea) panel.getComponentAt(i);
                    //fill chathistory
                    String oldHistory = currentTabHistory.getText();
                    String newHistory = oldHistory + "\n" + txt_username.getText() +": "+txt_sendingField.getText();
                    currentTabHistory.setText(newHistory);
                }
                else{
                    String oldhistory = txt_chatHistory.getText();
                    oldhistory = oldhistory + "\n" + txt_username.getText() +": "+txt_sendingField.getText();
                    txt_chatHistory.setText(oldhistory);
                
                }
                txt_sendingField.setText("");
                    
            } catch (IOException ex) {
                Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        userTabList.removeAll(userTabList);
        System.out.println("tablist gelöscht");
    }//GEN-LAST:event_cmd_sendActionPerformed