@Override
    public void actionPerformed(ActionEvent arg0) {
      if (panel == null) {
        panel = new AddFriendPanel();
      }
      panel.setTextField("");
      while (true) {
        int option = JOptionPane.showConfirmDialog(mainWindow, panel, "Add friend", JOptionPane.OK_CANCEL_OPTION,
            JOptionPane.PLAIN_MESSAGE);
        if (option == JOptionPane.CANCEL_OPTION) { // action canceled
          break;
        }
        String newFriend = panel.getText();
        if (newFriend.trim().isEmpty()) {
          showErrorMessage(FIELDS_EMPTY);
          continue;
        }
        if(newFriend.compareTo(client.getLoggedInUser().getUsername()) == 0) {
          showErrorMessage(CANT_ADD_YOURSELF);
          continue;
        }
        if (client.getLoggedInUser().getFriendByUsername(newFriend) != null) {
          showErrorMessage(ALREADY_FRIENDS);
          continue;
        }
        client.addFriend(newFriend);
        break;
      }
    }