package cse1030.games.boggle; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; /** * The controller for the Boggle app. * * @author CSE1030_F13_14 * */ public class BoggleController implements ActionListener { private Boggle model; private BoggleView view; /** * Creates a controller with no model and no view. */ public BoggleController() { this.model = null; this.view = null; } /** * Sets the controller to use the given model. * * @pre. model must not be null * * @param model the model that the controller should use */ public void setModel(Boggle model) { this.model = model; } /** * Sets the controller to use the given view. * * @pre. view must not be null * * @param view the view that the controller should use */ public void setView(BoggleView view) { this.view = view; } /** * Responds to events from the view. This method responds to an * event where the action command is either * BoggleView.ROLL_COMMAND or * BoggleView.SUBMIT_COMMAND. * * @param event an event emitted by the view * * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) */ @Override public void actionPerformed(ActionEvent event) { String command = event.getActionCommand(); if (command.equals(BoggleView.ROLL_COMMAND)) { // The player has clicked the roll button. // 1. ask the model to roll the dice // 2. tell the view about the dice } else if (command.equals(BoggleView.SUBMIT_COMMAND)) { // The player has clicked the submit button. // 1. get the word from the view // 2. ask the model if the word is correct or not // 3. tell the view if the word is correct or not } } }