This programming assignment continues the theme from Assignment 1.
In this assignment, you will provide a graphical user interface to the
forest fire simulation.
Just like Assignment 1, trees are placed
in a grid at random starting locations, and the simulation proceeds
as trees ignite or burn.
The simulation stops after a given number of time-steps.
Also, unlike Assignment 1, you will NOT be estimating anything
in this assignment.
Create a graphical user interface with the following features:
- A frame that displays the grid (landscape). Read in the size of
the grid from the screen.
You don't have to use a textbox - just the plain
reading from the screen from Module 3. But if you
want to use textfield's or textboxes, that would be fine.
- The following buttons:
- A "quit" button to quit the program.
- A "nextStep" button that completes
in one time-step. Thus, clicking multiple times on "nextStep"
will eventually result completing the simulation.
- A "completeRun" button that completes the current simulation
run (completes burning those trees that eventually must burn).
Thus, clicking on "completeRun" should produce the same resulting
screen as we would get after clicking "nextStep" as many times
as required to get to the final landscape (i.e., after all
the trees that could burn have burned).
- A "startNewRun" button that starts a new run with new
random initial locations.
- Implement a response to mouse-clicks so that a click on an un-burnt tree
ignites the tree. Implement your mouse clicks so that such
igniting can be done at any time during the simulation.
- Display the following data:
- Display the tree-type (1 or 2) of each tree. You could, for
example, draw a colored circle to represent a tree, and write
the tree-type inside the circle.
- Use a unique color depict "burnt" trees.
- Somewhere on the frame, display the number of type-1 trees
(and type-2 trees) that have burned. This number should be updated
as it changes during the simulation.
- Somewhere on the frame, display the number of burned,
currently burning and live trees.
Start by downloading Assign2.java:
- This file is similar to your template for Assignment 2, except
that no method in the Landscape class is called.
- Now all the input data, including the initial burn pattern is
given to the constructor of this class.
- To implement the GUI, make your Landscape extend
a frame:
- Make Landscape extend
JFrame, and create an additional panel that extends
JPanel so that you can override its
paintComponent() method.
- Before the very first click occurs, you should display the
initial landscape with all the trees intact except for the
trees in the initial ignition pattern.
Note:
- Since the majority of points in this assignment will be given
to the GUI, if you weren't able to complete Assignment 1, then
get this assignment working using only type-1 trees.
After that's working, you can add the features required to
handle type-2 trees.
Deliverables and submission:
- Write your code in a file called Assign2.java.
- Provide the source code for your program. NOTE: It is not necessary
to write all your all your code in the
same file. In fact it is better to place each appropriate class
(from Assignment 1, if you wish to use those) in a separate file.
Just make sure your main method is in
Assign2.java.
- What did you do to ensure that your code is working correctly?
You will also need to provide some evidence, test cases (and output)
to validate your program.
- Your code will be graded
on both correctness and documentation.
- Follow the
submission instructions carefully as usual.