15-200 Fall 2006

Homework Assignment 6

Helicopter Flight

Program Due: Thursday Nov. 02, 2006 at 11:59pm


Background:

This lab will require you to create a JApplet with a few event listeners. Before you start to implement the assignment take an extra look at the lecture and especially at supplemental code examples.


Objectives:


Instructions:

Design an applet (JApplet, actually) that has an animation scene of a helicopter flying over some terrain. The helicopter only moves up and down. When the mouse is pressed, the helicopter should rise. When the mouse button is not being pressed over the scene, the helicopter should sink towards the terrain. Meanwhile, the terrain should be moving off to the left. If the helicopter hits the terrain, the animation should stop. The applet should contain three buttons "Start", “Reset Terrain” and “Change Terrain Color” and a slider “Speed Control” that adjusts the speed of the passing terrain. “Start” should cause the helicopter to start sinking, “Reset Terrain” should create a new set of mountains and “Change Terrain Color” should randomly select a new color for the terrain.

You are to design two classes: Helicopter and HeliPanel.

The class Helicopter should implement three interfaces ActionListener, ChangeListener and MouseListener. In this class you create four panels (JPanel, actually). Let us call them tools, speedP, heli and appletPanel. The slider and an appropriate text label should be placed on the speedP. You will place all buttons and the speedP onto the tools panel. You will draw a helicopter and the terrain on the heli panel. And finally, you place these two panels onto the appletPanel panel. You need to implement five methods in this class:

The second class HeliPanel is responsible for actual drawing. You will need to implement paintComponent() method, repaintMotion() as well as three mutators (methods which change the fields variables). The constructor should initialize the terrain. The terrain can be represented by a list of integers for the heights of the mountains. Each number in the list should be generated by taking the preceding height and randomly adding +1, 0 or -1. The terrain can be displayed as adjoining rectangles or lines.


Extra credit (up to 10 points):

We will offer a few extra credit points if you make any significant additions to the applet, like implementation of a new event, placing a new button and/or displaying some type of message or animation when the helicopter crashes.


What You'll Need:

Download the lab.zip. Save it to your temp directory and unzip the files. You should see the following files:


Handing in your Solution:

You ftp your implementation to andrew.cmu.edu. Include Helicopter.java, HeliPanel.java and Helicopter.html