@Override
  public void windowClosing(WindowEvent e) {
    logger.debug("closing event received");
    int confirmResult =
        JOptionPane.showConfirmDialog((Component) view, "Are you sure?", "Leaving so soon?", 1);
    System.out.println(confirmResult);

    if (JOptionPane.OK_OPTION == confirmResult) {

      try {
        serverUpdater.processClientAction(
            new ClientAction(
                gameId, player, ActionType.QUIT, view.getGameType(), view.getChatText(), null));
        System.exit(0);

      } catch (RemoteException e1) {

        logger.fatal("cant' contact server", e1);
        e1.printStackTrace();
      } catch (SkrullException e1) {
        handleSkrullException(e1);
      } finally {
        // if there was an error quitting the game (like if the server wasn't there)
        // then still exit but with error status
        System.exit(1);
      }
    }
  }
  @Override
  public void actionPerformed(ActionEvent actionEvent) {

    gameId = view.getGameId();

    ActionType type = ActionType.valueOf(actionEvent.getActionCommand());

    try {
      switch (type) {
        case CHAT:
          serverUpdater.processClientAction(
              new ClientAction(gameId, player, type, view.getGameType(), view.getChatText(), null));
          break;

        case CREATE_GAME:
          // need to handle when no selection was made in the list and the user
          // chooses to start a new game

          // TODO: a builder or factory seems to be in order for the ClientActions
          GameType gameType = view.getGameType();
          serverUpdater.processClientAction(
              new ClientAction(gameId, player, type, gameType, view.getChatText(), null));
          serverUpdater.processClientAction(
              new ClientAction(
                  0, player, ActionType.QUIT, GameType.DEFAULT, view.getChatText(), null));

          break;

        case JOIN_GAME:
          // need to handle when user hits join but nothing is selected in the list

          String selectedGame[] = view.getJoinGameString().split(":");
          int index = Integer.parseInt(selectedGame[0]);
          GameType toJoinType = GameType.valueOf(selectedGame[1]);
          serverUpdater.processClientAction(
              new ClientAction(index, player, type, toJoinType, view.getChatText(), null));
          serverUpdater.processClientAction(
              new ClientAction(
                  0, player, ActionType.QUIT, GameType.DEFAULT, view.getChatText(), null));

          break;

        case MOVE:
          Move viewMove = new Move();
          actionEvent.getActionCommand(); // will set actionEvent To MOVE

          JButton buttonPressed = (JButton) actionEvent.getSource();
          int buttonIndex = Integer.parseInt(buttonPressed.getText());

          viewMove.setMoveIndex(buttonIndex);
          viewMove.setPlayer(player);

          serverUpdater.processClientAction(
              new ClientAction(
                  gameId, player, type, view.getGameType(), view.getChatText(), viewMove));
          break;

        case QUIT:
          int confirmResult =
              JOptionPane.showConfirmDialog((Component) view, "Return to main screen?", "Quit?", 1);
          System.out.println(confirmResult);

          if (JOptionPane.OK_OPTION == confirmResult) {

            try {
              serverUpdater.processClientAction(
                  new ClientAction(
                      gameId,
                      player,
                      ActionType.QUIT,
                      view.getGameType(),
                      view.getChatText(),
                      null));
              serverUpdater.processClientAction(getStartupAction());

              // System.exit(0);
            } catch (RemoteException e1) {

              logger.fatal("cant' contact server", e1);
              view.setBroadcastMessage(e1.getMessage());
            } catch (SkrullException e1) {
              handleSkrullException(e1);
            }
          }

          break;

        default:
          throw new UnsupportedOperationException(actionEvent + actionEvent.getActionCommand());
      }

    } catch (SkrullException ex) {
      handleSkrullException(ex);

    } catch (RemoteException ex) {
      view.setBroadcastMessage(ex.getMessage());
      logger.fatal("Can't contact server", ex);
    }
  }