CSE1030

Lab 7

Tue Nov 5 and Thu Nov 21
Due: Mon Nov 25 before 11:59PM

Introduction

The purpose of this lab is to implement the game Boggle™. In this lab you will:

Most of your time will be spent implementing the view (and studying the Swing component APIs). The model was mostly implemented in Lab 4, and the controller and application can be implemented with relative ease.

Using the Boggle™ App

Please review the description of the game Boggle™ from Lab 4 if you do not recall how the game is played. Your goal for this lab is to implement the following app:

Our Boggle™ app has many features:

You can play the Boggle™ app in the Prism lab using the command:

java -jar /cse/dept/www/course/classpath/1030/BoggleApp.jar

Lab Resources

The API for all of the classes in this lab can be found at the link below; note that these APIs include all of the documented private members to help you understand the code.

In eclipse, create a new project. In the project, create a new package named cse1030.games.boggle. Add the following files to the package:

Add the following JAR file to the project:

I recommend starting with the BoggleView; see the instructions that follow.

The BoggleView

Recall that the view in the model-view-controller pattern is the appearance of the application and the user-interface that is provided to the user. Our BoggleView object is made up of many Swing components:

  1. The red panel is the main content pane for the view. Its purpose is to contain the left, middle, and right panels, and to lay out those panels from left to right using a FlowLayout.
  2. The left blue panel contains the list of correct words and its label. It stacks the components from top to bottom using a BoxLayout.
  3. The right blue panel contains the list of incorrect words and its label. It stacks the components from top to bottom using a BoxLayout.
  4. The middle green panel is used to contain the orange panel that holds the dice and the black panel that holds the controls, and to lay out those panels from top to bottom using a BoxLayout.
  5. The orange panel contains the buttons representing the dice. It uses a GridLayout to arrange the dice in a grid.
  6. The black panel contains the various controls. It uses a FlowLayout to arrange the controls from left to right.

Completing BoggleView

The BoggleView class has a main method that creates and displays the view. If you run the view, you will see the left panel. As you complete methods, additional functionality should start to appear.

About half of the BoggleView class is implemented for you. Please examine the code provided, especially the fields that are in the class. You do not need to add any new fields to the class.

The first method you should complete is makeRightPanel(). This method creates the right hand panel that holds the list of incorrect words and its label. You can follow the implementation of makeLeftPanel() and the instructions in the commments.

The second method you should complete is makeMiddlePanel(). This method creates the middle panel that holds the the dice panel and the controls panel. You can follow the instructions provided in the comments.

The third method you should complete is makeControlPanel. This method creates the panel that holds the Clear button, the text field that displays the current word, the Submit button, and the Re-roll button. One button and the text field is created for you.

The fourth method you should complete is getWord. This method gets the text from the text field that displays the current word. You can find out how to do this by looking up the JTextField API. The controller uses this method to get word from the view so that it can ask the model to validate the word.

The fifth method you should complete is setDice. This method sets the text for each dice button. All you need to do is to transfer the current value of each die in dice to its corresponding button in this.diceButtons. The first die in dice corresponds to the first button in this.diceButtons, the second die corresponds to the second button, and so on.

The sixth method you should complete is setWordIsCorrect. This method adds the current word to the list of correct words if isValid is true; otherwise, it adds the current word to the list of incorrect words. The controller uses this method to inform the view that the word that was submitted is correct or incorrect. You can find out how to append a word to a text area by looking up the JTextArea API.

The seventh and eighth methods you should complete are clearCorrectWords and clearIncorrectWords. These methods clear the text areas that list the correct and incorrect words. You can find out how to set the text for a text area to an empty string by looking up the JTextArea API.

Finally, complete the method clearCurrentWord. This is the method that is called whenever the current word needs to be cleared. This occurs when the player clicks the Clear button and whenever a word is submitted and verified by the controller (i.e., at the end of setWordIsCorrect).

Completing BoggleApp

BoggleApp creates a controller, a model, and a view, informs the controller of the model and the view, and makes the view visible. The lectures slides show you how to do this (see, for example, SimpleApp).

By completing BoggleApp, you can run the app, but pressing the Submit or Re-roll buttons will produce no results until the controller is completed.

Completing BoggleController

BoggleController coordinates communication between the view and model. It does so through the actionPerformed method.

By completing actionPerformed, you can run the app, and roll the dice. Submitting a word will always result in the word being added to the list of correct words until you complete the model.

Completing Boggle

Boggle is the model from Lab 4. It has been enhanced to include a dictionary of approximately 80,000 English words. The dictionary is represented as a Set<String> where the strings are all lowercase English words.

Complete the method lookUp that checks if the given word is in the dictionary and is at least 3 letters in length. Once this is done, you should have a completed application.

Submit

submit 1030 L7 Boggle.java BoggleApp.java BoggleController.java BoggleView.java