Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Objectives Render (draw) the contents of a two-dimensional array. Use JOptionPane to control the processing of an application. Instructions Window-Based Game of Life. In Part

Objectives

Render (draw) the contents of a two-dimensional array.

Use JOptionPane to control the processing of an application.

Instructions

Window-Based Game of Life.

In Part I, you created an implementation of Life. The Part I implementation uses a two-dimensional array to represent the cells in the game. It used System.out to present the Life board to the user.

Now, in Part II, you are going to replace the textual output with a graphical output.

Create an output class for this application. Implement this in a separate class. (There may be other support classes that you will need to create.)

This class can extend java.awt.Component or javax.swing.JComponent.

This instance will need access to the two-dimensional array representing the cells. You can either pass the array as a parameter to the constructor, or you can pass the array each time you update the contents of the display.

This class should not be a Frame or JFrame. We will add this to a frame for display.

Create a frame to display your output class. This should be a JFrame. The layout of the frame is up to you.

In the application method, display the starting point for your Life implementation in the window, using your display class.

Design Decisions

There are a number of design decisions that are part of this assignment. The primary component that you are creating renders the 19x19 grid of cells which is the complete universe (board) for the Game of Life. However, each of the 381 individual cells can use the same code to display itself. There is a related design decision here. Is the size of the cell fixed? Or can it grow / shrink based on the size of the environment (the board).

This might suggest that the cells are themselves graphical components, with the board being some sort of container which holds the cells. Alternately, there could be a simple method (or two) of your board component that would take a Graphics object and a location (either int x, int y or a java.awt.Point) (and also, potentially a size) and then draw the appropriate graphical image at the given location.

Next Generation

Now, calculate the next generation. Display the next generation within the output class in the window.

To make it possible to examine the different generations, use javax.swing.JOptionPane to pause the application method. See the example code, JOptionDemo.

Insure that you can calculate the third generation of Life. In Part I, this was an extra credit option. As we move forward, this is no longer optional. You will need to have multiple generation support for Life by the end of the assignment.

Extra Credit

Modify the application to display as many generations as the user wants. You can use the showConfirmDialog method of JOptionPane. For more information about this method, see the documentation for the standard library.

Written Report

Write a report in which you describe:

how did you go about starting this project?

what works and what doesnt?

the surprises or problems you encountered while implementing this application

the most important thing(s) you learned from this assignment

what you would do differently next time

I expect a clear report that has some thought in it. It will be easiest if you take notes about the process as you work on the assignment, rather than waiting till the end to start the written report.

Evalution Criteria

Here are the coding evaluation criteria.

The code compiles and is complete.

The display component is in a separate class from the frame (JFrame / top-level window).

The display component is in a separate class from the two-dimensional array (Part I of the assignment).

The display component accurately renders the state of the game as represented within the array.

The display component is not responsible for initiating or calculating the next generation of the game.

The display component uses java.awt.Graphics to render the state of the game. (Using drawString or drawChars does not count.)

The display component arranges the cells of the game in a square. (You may assume that a pixels is a true square.)

The use of color is laudable.

The use of shapes is laudable.

The display of the boundries of each cell, whether dead or alive, is laudable.

Here are the style evaluation criteria.

There are comments that explain the functionality and design of each block of code. (Granted, "block of code" is indeed ambiguous. It is not a requirement to comment each line of code. However, it is unlikely that a single comment can accurately describe the design rationale for dozens of lines of code, especially where computation occurs.

Comments shall preceed the associated code.

The target length for a line of code is 80 characters, including the initial indent.

Each variable will include a simple explanation of its meaning / use.

A reason must be given for each variable field (instance variable or class variable). Why does this variable need to be shared?

The vertical alignment within the code clearly reflects the structure of the code. This includes both nested statements being indented and items at the same level of nesting sharing the same amount of indenting.

The placement of braces ({ and }) is uniform within the code for each type of usage. That is, the placement of braces for methods and constructors is consistent. The placement of braces for each type flow-of-control statement is consistent, minimally for that single flow-of-control statement.

Reasonable white space is included in the code. The white space is used to visually group the code to highlight the structure. In general, there is little need for more than two or three blanks lines together.

The written report addresses the questions posed.

-----------------------------------------------------

JOptionDemo.java code:

/** * A simple class demonstrating how the JOptionPane methods will * pause the progress of a method. */ public class JOptionDemo { /** * The demo code * @param args The command-line arguments */ public static void main(String[] args) { // Start by printing out part of a line. System.out.print("Hello w"); // Now pause the method by calling showMessageDialog. // This method call will complete after the message dialog is // dismissed. The use of null as the first argument centers the // message dialog box on the screen. javax.swing.JOptionPane.showMessageDialog(null, "Click OK to continue"); // Now, complete the output line. Notice that the output shows // no indication that it was interrupted. System.out.println("orld"); } } 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

What are the attributes of a technical decision?

Answered: 1 week ago

Question

How do the two components of this theory work together?

Answered: 1 week ago