Class ConnectXView

All Implemented Interfaces:
ActionListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible, RootPaneContainer, WindowConstants

public class ConnectXView extends JFrame implements ActionListener
This class is the view of our Extended Connect X our view has a message area, and a list of buttons the buttons will be arranged in a ROWS_IN_BUTTON_PANEL x COLUMNS_IN_BUTTON_PANEL Grid Players will use another set of buttons above the grid to select the column to place in All events will be passed to the controller

You do not need to make any changes to this code, but you do need to understand much of what is happening

See Also:
  • Constructor Details

    • ConnectXView

      public ConnectXView(int row, int col)

      This creates a screen for playing the game.

      Parameters:
      row - the number of rows you want in the Extended ConnectX grid
      col - the number of columns you want in the Extended ConnectX grid
      Pre:
      row > 0 and col > 0
      Post:
      [ a functional screen with a row x col grid of buttons will be created ]
  • Method Details

    • registerObserver

      public void registerObserver(ConnectXController c)

      This method registers argument as observer/listener of this; this must be done first, before any other methods of this class are called.

      Parameters:
      c - Controller to register
      Pre:
      [ c is a valid controller for this view ]
      Post:
      this.controller = c
    • actionPerformed

      public void actionPerformed(ActionEvent event)

      This is the callback method that gets called as part of the observer pattern.

      Specified by:
      actionPerformed in interface ActionListener
      Parameters:
      event - The event on the screen that is observed
      Post:
      [ button events will be sent to the controller ]
    • setMessage

      public void setMessage(String m)

      This method displays a message on the screen.

      Parameters:
      m - The message to display in our text area
      Post:
      [ the this.message text = m ]
    • setMarker

      public void setMarker(int row, int col, char player)

      This method displays a player token on the screen.

      Parameters:
      row - The row of the button in our grid
      col - The column of the button in our grid
      player - The player who will now claim that button
      Pre:
      0 <= row < ROWS_IN_BUTTON_PANEL and 0 < = col < = COLUMNS_IN_BUTTON_PANEL
      Post:
      [ the button at row, col will display the character for the player ]