Copyright © 1998 Sita Ramakrishnan, Monash University All rights reserved

Light Views

HomeCase StudiesOO TheoryHelp

Light Views Icon


Case Studies

Introduction

Event Testing

Inheritance & Collaboration

State Chart Diagram (UML)

Demo Description

BeachMap AppletBeachParking Applet BeachInfo Applet BeachStatistic Applet Beaches & Parking

Quiz

Questionnaire

Beaches and Parking Case Study

BeachInfo applet

Demonstrations:

BeachInfo's purpose is to display the sample picture(s) of a beach and play a sound clip to go with the picture assuming that this data exists. From this applet, the user can interacts with BeachParking and BeachStatistic, which will be looked at later.

Most of the user interactions will take place in this applet. Initially when it is loaded and started, nothing is visible thus disabling the user from doing anything useful on this applet. After a beach is selected from the map on BeachMap applet, then the fun begins.

As a result, a MapData object is passed to it. Before doing anything with the data, a data validation is carried out to make sure the data is valid. If everything is OK, then the data is processed.

If more than one picture exists they are displayed one after another with delay in between them (animation). This process is controlled by a separate thread of execution so that the applet can carry other tasks too such as playing the sound clip or waiting to events to occur.

BeachInfo class extends from the Applet class. To view the inheritance hierarchy, go to the Inheritance and Collaboration section. Furthermore it implements three interfaces, they are the MouseListener interface, ActionListener and Runnable.

 To enable itself to receive mouse events such as mouse clicks, it implements the MouseListener. This interface defines the signature of the methods that must be implemented by the BeachInfo applet. Only one component of BeachInfo applet is interested in capturing the mouse clicks, the canvas where the picture(s) are displayed. When a mouse click is detected, the BeachInfo is informed about the event. As the result the animation is suspended or resumed depending the on the current status of the thread.

BeachInfo

The ActionListener interface is used for receiving events like pressing a button. BeachInfo has three command buttons that the user can click on. They are labeled `Statistics' to display the bar chart on BeachStatistic applet; `Parking' to display the parking information on BeachParking; and `Play' or `Stop' to play or mute the sound clip. These buttons is only visible when required.

All the three buttons register its parent, i.e. the applet, as the event receiver and handler. All three buttons generate the same event when they are selected. To differentiate the originator of the event, the label of button is checked against the command name contained in an  ActionEvent object. This object stores the details of the event. The event handler method is called actionPerformed().

The last interface, Runnable interface, is required to create a new thread of execution to control the animation (to display one picture after another). The interface only has one method, run(). The method is called when the thread is started via a call to Thread.start() method.

The class diagram for the applet is provided on the right hand side of the screen to show the data members (on top of the line) and the methods of the applet.

 

 


Funded by Committee of University Teaching And Staff Development (CUTSD) through DEETYA, 1998