/** Handles all button events and updates the view. */
 public void actionPerformed(ActionEvent e) {
   searchMetrics = null;
   if (e == null || e.getSource() == clearButton) {
     currState = game.getInitialState();
   } else if (!game.isTerminal(currState)) {
     if (e.getSource() == proposeButton) {
       proposeMove();
     } else if (e.getSource() instanceof GridElement) {
       GridElement el = (GridElement) e.getSource();
       currState = game.getResult(currState, el.col); // take next
       // turn
     }
   }
   repaint(); // paint all disks!
   updateStatus();
 }
 /** Updates the status bar. */
 private void updateStatus() {
   String statusText;
   if (!game.isTerminal(currState)) {
     String toMove = (String) game.getPlayer(currState);
     statusText = "Next move: " + toMove;
     statusBar.setForeground(toMove.equals("red") ? Color.RED : Color.YELLOW);
   } else {
     String winner = null;
     for (int i = 0; i < 2; i++)
       if (game.getUtility(currState, game.getPlayers()[i]) == 1) winner = game.getPlayers()[i];
     if (winner != null) statusText = "Color " + winner + " has won. Congratulations!";
     else statusText = "No winner :-(";
     statusBar.setForeground(Color.WHITE);
   }
   if (searchMetrics != null) statusText += "    " + searchMetrics;
   statusBar.setText(statusText);
 }