CIS 120 Spring 2008

Homework 6: Minesweeper GUI

Due: Friday March 28th at 5PM

Recall the Minesweeper homework you did earlier this semester where you implemented the internal workings of the game. This time around, you will be creating a GUI similar to the one we provided.

This is an example of the Model/View/Controller design pattern where the Minesweeper and Cell classes are the Model and the Viewer class is the Viewer and Controller.

Files to submit:

Supplied Files:

Javadocs

Minesweeper GUI (80 pts)

Your job is to write this application, contained in the class Viewer (which extends the class javax.swing.JFrame), whose constructor opens the 500 x 500 pixel frame shown below. Your window should look exactly like the one below, modulo any OS-based differences, for a 10 x 10 game. When the window is closed, the application should terminate. You may include additional methods in the Viewer class, but be sure to implement all the methods specified in our Javadocs.

Executing the following interaction should generate the window below:
> Minesweeper game = new Minesweeper(10, 10, 10);

Game Play

Feel free to go back to Homework 1 and use the jar file to clarify any questions about functionality.

Javadoc Comments (20 pts)

Since you will be designing your own methods and classes, we would like you to carefully comment your code. To this end, Java provides javadoc functionality, demonstrated below.
/**
* Returns an Image object that can then be painted on the screen.
* The url argument must specify an absolute {@link URL}. The name
* argument is a specifier that is relative to the url argument.
* <p>
* This method always returns immediately, whether or not the
* image exists. When this applet attempts to draw the image on
* the screen, the data will be loaded. The graphics primitives
* that draw the image will incrementally paint on the screen.
*
* @param url an absolute URL giving the base location of the image
* @param name the location of the image, relative to the url argument
* @return the image at the specified URL
* @see Image
*/
public Image getImage(URL url, String name) {
   try {
     return getImage(new URL(url, name));
   } catch (MalformedURLException e) {
     return null;
   }
}

Generates a webpage that looks like this:

getImage

public Image getImage(URL url,
                      String name)
Returns an Image object that can then be painted on the screen. The url argument must specify an absolute URL. The name argument is a specifier that is relative to the url argument.

This method always returns immediately, whether or not the image exists. When this applet attempts to draw the image on the screen, the data will be loaded. The graphics primitives that draw the image will incrementally paint on the screen.

Parameters:
url - an absolute URL giving the base location of the image
name - the location of the image, relative to the url argument
Returns:
the image at the specified URL
See Also:
Image

For a lengthy guide, please see the following tutorial from Sun: Writing Javadoc Comments.

For each method, we expect a description of:

Extra Credit

File to submit:ViewerResize.java
Calculate the size of the window based upon the size of the game. For example, a 10 x 10 and a 15 x 15 game will occupy windows of different sizes. Place your implementation in a separate class called ViewerResize and document the changes you make in the javadocs.

Submission

Create a zip file called Javadocs.zip of the docs folder that contains the javadocs generated from your code and submit it along with your Viewer.java file.

Grading

All submissions will be hand graded for functionality of the GUI and the completeness of the Javadoc comments. A difference of a few pixels is OK.