Appendix I – Elevator View

Download Report

Transcript Appendix I – Elevator View

Appendix F – Elevator View
Outline
F.1
F.2
F.3
F.4
F.5
F.6
F.7
Introduction
Class Objects
Class Constants
Class Constructor
Event Handling
F.5.1 ElevatorMoveEvent types
F.5.2 PersonMoveEvent types
F.5.3 DoorEvent types
F.5.4 ButtonEvent types
F.5.5 BellEvent types
F.5.6 LightEvent types
Artifacts Revisited
Conclusion
 2003 Prentice Hall, Inc. All rights reserved.
F.1 Introduction
• Class ElevatorView
– Graphical representation of elevator-simulation model
– Largest class in simulation
 2003 Prentice Hall, Inc. All rights reserved.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
Outline
// ElevatorView.java
// View for ElevatorSimulation
package com.deitel.jhtp5.elevator.view;
ElevatorView.ja
va
ElevatorView
displays the elevator
simulation model.
// Java core packages
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.applet.*;
// Java extension package
import javax.swing.*;
ElevatorView implements
Lines 18-20
ElevatorSimulationListener,
which inherits from all listener
interfaces
Lines
23-24
// Deitel packages
import com.deitel.jhtp5.elevator.event.*;
import com.deitel.jhtp5.elevator.ElevatorConstants;
public class ElevatorView extends JPanel
implements ActionListener, ElevatorSimulationListener,
ElevatorConstants {
// ElevatorView dimensions
private static final int VIEW_WIDTH = 800;
private static final int VIEW_HEIGHT = 435;
Constants for width and height
of ElevatorView
// offset for positioning Panels in ElevatorView
private static final int OFFSET = 10;
 2003 Prentice Hall, Inc.
All rights reserved.
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Elevator repaints components every 50 ms
private static final int ANIMATION_DELAY = 50;
// horizontal distance constants
private static final int PERSON_TO_BUTTON_DISTANCE = 400;
private static final int BUTTON_TO_ELEVATOR_DISTANCE = 50;
private static final int PERSON_TO_ELEVATOR_DISTANCE =
PERSON_TO_BUTTON_DISTANCE + BUTTON_TO_ELEVATOR_DISTANCE;
// times walking to Floor's Button and Elevator
private static final int TIME_TO_BUTTON = 3000; // 3 seconds
private static final int TIME_TO_ELEVATOR = 1000; // 1 second
Outline
Constant for animation
(refresh) rate
ElevatorView.ja
Constants for
va distances
that Person
must travel
ElevatorView
displays the elevator
simulation model.
Time constants for
distancesLine
Person
30
travels
Lines 33-36
// time traveling in Elevator (5 seconds)
private static final int ELEVATOR_TRAVEL_TIME = 5000;
// Door images for animation
private static final String doorFrames[] = {
"images/door1.png", "images/door2.png", "images/door3.png",
"images/door4.png", "images/door5.png" };
// Person images for animation
private static final String personFrames[] = {
"images/bug1.png", "images/bug2.png", "images/bug3.png",
"images/bug4.png", "images/bug5.png", "images/bug6.png",
"images/bug7.png", "images/bug8.png" };
Lines 39-40
Constant for time
required
Line 43to travel
between Floors
Lines 46-54
Constants for names of
graphics files for Door
and Person
 2003 Prentice Hall, Inc.
All rights reserved.
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Light images for animation
private static final String lightFrames[] = {
"images/lightOff.png", "images/lightOn.png" };
// Floor Light images for animation
private static final String firstFloorLightFrames[] = {
"images/firstFloorLightOff.png",
"images/firstFloorLightOn.png" };
private static final String secondFloorLightFrames[] = {
"images/secondFloorLightOff.png",
"images/secondFloorLightOn.png", };
Outline
ElevatorView.ja
va
ElevatorView
Constants
forthe
names
of
displays
elevator
graphics
files formodel.
Light,
simulation
Button and Bell
Lines 57-84
// Floor Button images for animation
private static final String floorButtonFrames[] = {
"images/floorButtonUnpressed.png",
"images/floorButtonPressed.png",
"images/floorButtonLit.png" };
// Elevator Button images for animation
private static final String elevatorButtonFrames[] = {
"images/elevatorButtonUnpressed.png",
"images/elevatorButtonPressed.png",
"images/elevatorButtonLit.png" };
// Bell images for animation
private static final String bellFrames[] = {
"images/bell1.png", "images/bell2.png",
"images/bell3.png" };
 2003 Prentice Hall, Inc.
All rights reserved.
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
Outline
private static final String floorImage =
"images/floor.png";
private static final String ceilingImage =
"images/ceiling.png";
private static final String elevatorImage =
"images/elevator.png";
private static final String wallImage =
"images/wall.jpg";
private static final String elevatorShaftImage =
"images/elevatorShaft.png";
// audio files
private static
private static
private static
private static
private static
private static
private static
final
final
final
final
final
final
final
// ImagePanels for
private ImagePanel
private ImagePanel
private ImagePanel
private ImagePanel
private ImagePanel
String
String
String
String
String
String
String
ElevatorView.ja
Ceiling and
wall are not
in model,va
but we display
themElevatorView
for realism
displays the elevator
simulation model.
Lines 88-89 and 92-93
bellSound = "bell.wav";
doorOpenSound = "doorOpen.wav";
doorCloseSound = "doorClose.wav";
elevatorSound = "elevator.au";
buttonSound = "button.wav";
walkingSound = "walk.wav";
elevatorMusicSound = "liszt.mid";
Floors, ElevatorShaft, wall and
firstFloorPanel;
secondFloorPanel;
elevatorShaftPanel;
wallPanel;
ceilingPanel;
Constants for names
Lines 98-103
of sound-clip files
Line 104
Lines 107-111
Constant for name of
“elevator music” file
ceiling ImagePanels represent
stationary objects in model (e.g.,
Floor, ElevatorShaft)
 2003 Prentice Hall, Inc.
All rights reserved.
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// MovingPanels for Elevator
private MovingPanel elevatorPanel;
// AnimatedPanels for
private AnimatedPanel
private AnimatedPanel
private AnimatedPanel
private AnimatedPanel
private AnimatedPanel
private AnimatedPanel
private AnimatedPanel
private AnimatedPanel
Buttons, Bell, Lights and Door
firstFloorButtonPanel;
secondFloorButtonPanel;
elevatorButtonPanel;
bellPanel;
elevatorLightPanel;
firstFloorLightPanel;
secondFloorLightPanel;
doorPanel;
// List containing AnimatedPanels for all Person objects
private java.util.List personAnimatedPanels;
// AudioClips for
private AudioClip
private AudioClip
private AudioClip
private AudioClip
private AudioClip
private AudioClip
sound effects
bellClip;
doorOpenClip;
doorCloseClip;
elevatorClip;
buttonClip;
walkClip;
// ElevatorMusic to play in Elevator
private AudioClip elevatorMusicClip;
Outline
MovingPanels represent
objects that can move and
have only one associated
ElevatorView.ja
AnimatedPanels
represent
image (e.g., Elevator)
objects in model va
with multiple
ElevatorView
images (e.g., Button, Person,
the elevator
Light, Bell displays
and Door)
simulation model.
Line 114
Lines 117-124
List stores AnimatedPanels
127
associated withLine
Persons
AudioClips for playing sound clips
Lines 130-135
Line 138
elevatorMusicClip plays music
when Person rides Elevator
 2003 Prentice Hall, Inc.
All rights reserved.
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
// Timer for animation controller;
private javax.swing.Timer animationTimer;
// distance from top of screen to display Floors
private int firstFloorPosition;
private int secondFloorPosition;
// Elevator's velocity
private double elevatorVelocity;
// ElevatorView constructor
public ElevatorView()
{
// specifiy null Layout
super( null );
instantiatePanels();
placePanelsOnView();
initializeAudio();
Outline
Timer determines
when to redraw
images
ElevatorView.ja
va
ElevatorView
displays the elevator
simulation model.
Line 141
Using null layout
Line 154
allows us to display
images anywhere on
Lines 165-168
ElevatorView
// calculate distance Elevator travels
double floorDistance =
firstFloorPosition - secondFloorPosition;
// calculate time needed for travel
double time = ELEVATOR_TRAVEL_TIME / ANIMATION_DELAY;
// determine Elevator velocity (rate = distance / time)
elevatorVelocity = ( floorDistance + OFFSET ) / time;
Calculate velocity
used by Elevator’s
ImagePanel
 2003 Prentice Hall, Inc.
All rights reserved.
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
Outline
// start animation Thread
startAnimation();
Starting Timer
starts animation
ElevatorView.ja
va
ElevatorView
displays the elevator
simulation model.
} // end ElevatorView constructor
// instantiate all Panels (Floors, Elevator, etc.)
private void instantiatePanels()
{
// instantiate ImagePanels representing Floors
firstFloorPanel = new ImagePanel( 0, floorImage );
secondFloorPanel = new ImagePanel( 0, floorImage );
Instantiate ImagePanels
Line 171
for Floors
Lines 179-180
// calculate first and second Floor positions
firstFloorPosition =
VIEW_HEIGHT - firstFloorPanel.getHeight();
secondFloorPosition =
( int ) ( firstFloorPosition / 2 ) - OFFSET;
Line 191
Lines 194-195
firstFloorPanel.setPosition( 0, firstFloorPosition );
secondFloorPanel.setPosition( 0, secondFloorPosition );
wallPanel = new ImagePanel( 0, wallImage );
// create and position ImagePanel for ElevatorShaft
elevatorShaftPanel =
new ImagePanel( 0, elevatorShaftImage );
Instantiate ImagePanel
for wall (not used in model)
Instantiate ImagePanel
for ElevatorShaft
 2003 Prentice Hall, Inc.
All rights reserved.
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
Outline
double xPosition = PERSON_TO_ELEVATOR_DISTANCE + OFFSET;
double yPosition =
firstFloorPosition - elevatorShaftPanel.getHeight();
elevatorShaftPanel.setPosition( xPosition, yPosition );
// create and position ImagePanel for ceiling
ceilingPanel = new ImagePanel( 0, ceilingImage );
ElevatorView.ja
va
ElevatorView
Instantiate ImagePanel for
displays the elevator
ceiling (not used in model)
simulation model.
yPosition = elevatorShaftPanel.getPosition().getY() ceilingPanel.getHeight();
Line 204
ceilingPanel.setPosition( xPosition, yPosition );
// create and position MovingPanel for Elevator
elevatorPanel = new MovingPanel( 0, elevatorImage );
Line 212
Instantiate
MovingPanel
Lines 219-220
for Elevator
yPosition = firstFloorPosition - elevatorPanel.getHeight();
elevatorPanel.setPosition( xPosition, yPosition );
// create and position first Floor Button
firstFloorButtonPanel =
new AnimatedPanel( 0, floorButtonFrames );
Instantiate AnimatedPanel
for Button on first Floor
xPosition = PERSON_TO_BUTTON_DISTANCE + 2 * OFFSET;
yPosition = firstFloorPosition - 5 * OFFSET;
firstFloorButtonPanel.setPosition( xPosition, yPosition );
 2003 Prentice Hall, Inc.
All rights reserved.
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
int floorButtonPressedFrameOrder[] = { 0, 1, 2 };
firstFloorButtonPanel.addFrameSequence(
floorButtonPressedFrameOrder );
// create and position second Floor Button
secondFloorButtonPanel =
new AnimatedPanel( 1, floorButtonFrames );
Outline
AnimatedPanels use
int arrays that ElevatorView.ja
determine
their image sequences
va
Instantiate AnimatedPanel
ElevatorView
for Button on second Floor
displays the elevator
simulation model.
xPosition = PERSON_TO_BUTTON_DISTANCE + 2 * OFFSET;
yPosition = secondFloorPosition - 5 * OFFSET;
secondFloorButtonPanel.setPosition( xPosition, yPosition );
secondFloorButtonPanel.addFrameSequence(
floorButtonPressedFrameOrder );
Lines 226-228
Lines 231-232
Instantiate AnimatedPanel
Lines 242-243
for Light on first Floor
// create and position Floor Lights
firstFloorLightPanel =
new AnimatedPanel( 0, firstFloorLightFrames );
Lines 250-251
xPosition = elevatorPanel.getLocation().x - 4 * OFFSET;
yPosition =
firstFloorButtonPanel.getLocation().y - 10 * OFFSET;
firstFloorLightPanel.setPosition( xPosition, yPosition );
secondFloorLightPanel =
new AnimatedPanel( 1, secondFloorLightFrames );
Instantiate AnimatedPanel
for Light on second Floor
 2003 Prentice Hall, Inc.
All rights reserved.
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
yPosition =
secondFloorButtonPanel.getLocation().y - 10 * OFFSET;
secondFloorLightPanel.setPosition( xPosition, yPosition );
// create and position Door AnimatedPanels
doorPanel = new AnimatedPanel( 0, doorFrames );
int doorOpenedFrameOrder[] = { 0, 1, 2, 3, 4 };
int doorClosedFrameOrder[] = { 4, 3, 2, 1, 0 };
doorPanel.addFrameSequence( doorOpenedFrameOrder );
doorPanel.addFrameSequence( doorClosedFrameOrder );
// determine where Door is located relative to Elevator
yPosition =
elevatorPanel.getHeight() - doorPanel.getHeight();
doorPanel.setPosition( 0, yPosition );
Outline
Instantiate
AnimatedPanel for
Door inElevatorView.ja
Elevator
(Note: wevado not show
Doors ElevatorView
on Floors,
becausedisplays
they would
the elevator
obscure Person
when
simulation
model.
riding Elevator)
Line 258
Line 271
Instantiate AnimatedPanel
for Light inside
Elevator
Line
275
// create and position Light AnimatedPanel
elevatorLightPanel = new AnimatedPanel( 0, lightFrames );
elevatorLightPanel.setPosition( OFFSET, 5 * OFFSET );
// create and position Bell AnimatedPanel
bellPanel = new AnimatedPanel( 0, bellFrames );
Instantiate AnimatedPanel
for Bell inside Elevator
yPosition = elevatorLightPanel.getPosition().getY() +
elevatorLightPanel.getHeight() + OFFSET;
bellPanel.setPosition( OFFSET, yPosition );
int bellRingAnimation[] = { 0, 1, 0, 2 };
bellPanel.addFrameSequence( bellRingAnimation );
 2003 Prentice Hall, Inc.
All rights reserved.
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
Outline
// create and position Elevator's Button AnimatedPanel
Instantiate AnimatedPanel
elevatorButtonPanel =
new AnimatedPanel( 0, elevatorButtonFrames );
for Button inside Elevator
yPosition = elevatorPanel.getHeight() - 6 * OFFSET;
elevatorButtonPanel.setPosition( 10 * OFFSET, yPosition );
int buttonPressedFrameOrder[] = { 0, 1, 2 };
elevatorButtonPanel.addFrameSequence(
buttonPressedFrameOrder );
// create List to store Person AnimatedPanels
personAnimatedPanels = new ArrayList();
ElevatorView.ja
va
ElevatorView
displays the elevator
simulation model.
Lines 285-286
Instantiate ArrayList
to store
references to AnimatedPanel’s
296
associated withLine
Person’s
} // end method instantiatePanels
Lines 305-314
// place all Panels on ElevatorView
private void placePanelsOnView()
{
// add Panels to ElevatorView
add( firstFloorPanel );
add( secondFloorPanel );
add( ceilingPanel );
add( elevatorPanel );
add( firstFloorButtonPanel );
add( secondFloorButtonPanel );
add( firstFloorLightPanel );
add( secondFloorLightPanel );
add( elevatorShaftPanel );
add( wallPanel );
Add ImagePanels
to ElevatorView
 2003 Prentice Hall, Inc.
All rights reserved.
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
// add Panels to Elevator's MovingPanel
elevatorPanel.add( doorPanel );
elevatorPanel.add( elevatorLightPanel );
elevatorPanel.add( bellPanel );
elevatorPanel.add( elevatorButtonPanel );
} // end method placePanelsOnView
// get sound effects and elevatorMusic
private void initializeAudio()
{
// create AudioClip sound effects from audio files
SoundEffects sounds = new SoundEffects();
sounds.setPathPrefix( "sounds/" );
Outline
Add ImagePanels for
elevator’s door, light bell and
ElevatorView.ja
button to the ImagePanel
va
associated with Elevator
ElevatorView
displays the elevator
simulation model.
Lines 316-319
SoundEffects object
Line 327
creates AudioClips
that play sound clips
Lines 330-336
bellClip = sounds.getAudioClip( bellSound );
doorOpenClip = sounds.getAudioClip( doorOpenSound );
doorCloseClip = sounds.getAudioClip( doorCloseSound );
Use SoundEffects
elevatorClip = sounds.getAudioClip( elevatorSound );
object to obtain references
buttonClip = sounds.getAudioClip( buttonSound );
to AudioClips
walkClip = sounds.getAudioClip( walkingSound );
elevatorMusicClip = sounds.getAudioClip( elevatorMusicSound );
} // end method initializeAudio
 2003 Prentice Hall, Inc.
All rights reserved.
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
Outline
// starts animation by repeatedly drawing images to screen
public void startAnimation()
{
if ( animationTimer == null ) {
ElevatorView.ja
Method startAnimation
starts
animationTimer =
va animation
Timer, which starts
new javax.swing.Timer( ANIMATION_DELAY, this );
ElevatorView
animationTimer.start();
displays the elevator
}
else
simulation model.
if ( !animationTimer.isRunning() )
animationTimer.restart();
Lines 341-352
}
Lines 355-358
// stop animation
public void stopAnimation()
{
animationTimer.stop();
}
Method stopAnimation stops
Lines
361-381
Timer, which stops
animation
Lines 363-366
// update AnimatedPanels animation in response to Timer
public void actionPerformed( ActionEvent actionEvent )
{
elevatorPanel.animate();
firstFloorButtonPanel.animate();
secondFloorButtonPanel.animate();
Timer invokes method
actionPerformed every 50
Animate ImagePanels for
(ANIMATION_DELAY) milliseconds
Elevator and Floors
 2003 Prentice Hall, Inc.
All rights reserved.
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
Outline
Iterator iterator = getPersonAnimatedPanelsIterator();
while ( iterator.hasNext() ) {
// get Person's AnimatedPanel from Set
AnimatedPanel personPanel =
( AnimatedPanel ) iterator.next();
personPanel.animate(); // update panel
}
ElevatorView.ja
va
ElevatorView
displays the elevator
simulation
model.
Animate ImagePanels
for Persons
Lines 370-377
repaint(); // paint all Components
} // end method actionPerformed
Line 388
private Iterator getPersonAnimatedPanelsIterator()
{
// obtain iterator from List
synchronized( personAnimatedPanels )
{
return new ArrayList( personAnimatedPanels ).iterator();
}
}
Lines 393-407
// stop sound clip of Person walking
private void stopWalkingSound()
{
// stop playing walking sound
walkClip.stop();
Obtain the Iterator of the
ArrayList of (Person)
AnimatedPanels
Stop sound clip played by ElevatorView when a Person walks
 2003 Prentice Hall, Inc.
All rights reserved.
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
Outline
Iterator iterator = getPersonAnimatedPanelsIterator();
// but if Person is still walking, then keep playing
while ( iterator.hasNext() ) {
AnimatedPanel panel = ( AnimatedPanel ) iterator.next();
if ( panel.getXVelocity() != 0 )
walkClip.loop();
}
} // end method stopWalkingSound
If a Person is still walking,
continue the sound clip
Lines 401-406
// returns Person AnimatedPanel with proper identifier
private AnimatedPanel getPersonPanel( PersonMoveEvent event )
{
Iterator iterator = getPersonAnimatedPanelsIterator();
while ( iterator.hasNext() ) {
// get next AnimatedPanel
AnimatedPanel personPanel =
( AnimatedPanel ) iterator.next();
ElevatorView.ja
va
ElevatorView
displays the elevator
simulation model.
Lines 410-428
Obtain AnimatedPanel
associated with Person that
sent the PersonMoveEvent
// return AnimatedPanel with identifier that matches
if ( personPanel.getID() == event.getID() )
return personPanel;
}
 2003 Prentice Hall, Inc.
All rights reserved.
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
// return null if no match with correct identifier
return null;
} // end method getPersonPanel
Invoked when Elevator
has departed from Floor
// invoked when Elevator has departed from Floor
public void elevatorDeparted( ElevatorMoveEvent moveEvent )
{
String location =
moveEvent.getLocation().getLocationName();
// determine if Person is on Elevator
Iterator iterator = getPersonAnimatedPanelsIterator();
while ( iterator.hasNext() ) {
Outline
ElevatorView.ja
va
ElevatorView
displays the elevator
simulation model.
Line 431
Lines 439-471
Determine whether Person
is on Elevator
AnimatedPanel personPanel =
( AnimatedPanel ) iterator.next();
double yPosition = personPanel.getPosition().getY();
String panelLocation;
// determine on which Floor the Person entered
if ( yPosition > secondFloorPosition )
panelLocation = FIRST_FLOOR_NAME;
else
panelLocation = SECOND_FLOOR_NAME;
 2003 Prentice Hall, Inc.
All rights reserved.
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
int xPosition =
( int ) personPanel.getPosition().getX();
// if Person is inside Elevator
if ( panelLocation.equals( location )
&& xPosition > PERSON_TO_BUTTON_DISTANCE + OFFSET ) {
// remove Person AnimatedPanel from ElevatorView
remove( personPanel );
Outline
ElevatorView.ja
va
ElevatorView
displays the elevator
simulation model.
// add Person AnimatedPanel to Elevator
elevatorPanel.add( personPanel, 1 );
Lines 457-470
personPanel.setLocation( 2 * OFFSET, 9 * OFFSET );
personPanel.setMoving( false );
Lines 474-479
If Person is inside Elevator,
personPanel.setAnimating( false );
remove Person from ElevatorpersonPanel.setVelocity( 0, 0 );
View and add Person to Elevator
personPanel.setCurrentFrame( 1 );
}
} // end while loop
// determine Elevator velocity depending on Floor
if ( location.equals( FIRST_FLOOR_NAME ) )
elevatorPanel.setVelocity( 0, -elevatorVelocity );
else
if ( location.equals( SECOND_FLOOR_NAME ) )
elevatorPanel.setVelocity( 0, elevatorVelocity );
Determine Elevator
velocity depending on Floor
 2003 Prentice Hall, Inc.
All rights reserved.
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
// begin moving Elevator and play Elevator music
elevatorPanel.setMoving( true );
if ( elevatorClip != null )
elevatorClip.play();
elevatorMusicClip.play();
} // end method elevatorDeparted
Outline
Set Elevator to moving state, then
play sound effect andElevatorView.ja
music associated
with the Elevator’s
va movement
ElevatorView
displays the elevator
simulation model.
// invoked when Elevator has arrived at destination Floor
public void elevatorArrived( ElevatorMoveEvent moveEvent )
{
// stop Elevator and music
elevatorPanel.setMoving( false );
elevatorMusicClip.stop();
double xPosition = elevatorPanel.getPosition().getX();
double yPosition;
Invoked
Lineswhen
482-487
Elevator has
arrived
at Floor
Line
492
Lines
495-496
Set Elevator to
waiting
state
and stop music associated with
Lines
502-509
the Elevator’s
movement
// set Elevator's position to either first or second Floor
if ( elevatorPanel.getYVelocity() < 0 )
yPosition =
secondFloorPosition - elevatorPanel.getHeight();
else
yPosition =
firstFloorPosition - elevatorPanel.getHeight();
elevatorPanel.setPosition( xPosition, yPosition );
Set Elevator’s ycoordinate to that of the
Floor on which the
Elevator arrived
} // end method elevatorArrived
 2003 Prentice Hall, Inc.
All rights reserved.
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
// invoked when Person has been created in model
public void personCreated( PersonMoveEvent personEvent )
{
int personID = personEvent.getID();
String floorLocation =
personEvent.getLocation().getLocationName();
// create AnimatedPanel representing Person
AnimatedPanel personPanel =
new AnimatedPanel( personID, personFrames );
Invoked when user Outline
creates
Person in simulation
ElevatorView.ja
Determine
va which
PersonElevatorView
was created
and on what
Floor
displays
the elevator
simulation
model.
Create AnimatedPanel
to
represent Person in view
Line 514
// determine where Person should be drawn initially
// negative xPosition ensures Person drawn offscreen
double xPosition = - personPanel.getWidth();
double yPosition = 0;
if ( floorLocation.equals( FIRST_FLOOR_NAME ) )
yPosition = firstFloorPosition +
( firstFloorPanel.getHeight() / 2 );
else
Lines 516-519
Position
Person’s
Lines
522-523
AnimatedPanel outside
the view, Lines
so the 530-541
Person
does not suddenly “appear.”
if ( floorLocation.equals( SECOND_FLOOR_NAME ) )
yPosition = secondFloorPosition +
( secondFloorPanel.getHeight() / 2 );
yPosition -= personPanel.getHeight();
personPanel.setPosition( xPosition, yPosition );
 2003 Prentice Hall, Inc.
All rights reserved.
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
// add some animations for each Person
int walkFrameOrder[] = { 1, 0, 1, 2 };
int pressButtonFrameOrder[] = { 1, 3, 3, 4, 4, 1 };
int walkAwayFrameOrder[] = { 6, 5, 6, 7 };
personPanel.addFrameSequence( walkFrameOrder );
personPanel.addFrameSequence( pressButtonFrameOrder );
personPanel.addFrameSequence( walkAwayFrameOrder );
// have Person begin walking to Elevator
personPanel.playAnimation( 0 );
personPanel.setLoop( true );
personPanel.setAnimating( true );
personPanel.setMoving( true );
// determine Person velocity
double time =
( double ) ( TIME_TO_BUTTON / ANIMATION_DELAY );
double xDistance = PERSON_TO_BUTTON_DISTANCE 2 * OFFSET + personPanel.getSize().width;
double xVelocity = xDistance / time;
Outline
Add animationElevatorView.ja
sequences
vapressing
(e.g., walking and
buttons) for theElevatorView
Person
displays the elevator
simulation model.
Set the Person’s
AnimatedPanel
to 544-549
Lines
its moving state (i.e.,
walking to Elevator)
Lines 552-555
Lines 558-563
Calculate Person’s velocity
and distance to Elevator
personPanel.setVelocity( xVelocity, 0 );
personPanel.setAnimationRate( 1 );
walkClip.loop(); // play sound clip of Person walking
 2003 Prentice Hall, Inc.
All rights reserved.
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
// store in personAnimatedPanels
synchronized( personAnimatedPanels )
{
personAnimatedPanels.add( personPanel );
}
Outline
Add Person’s
AnimatedPanel
ElevatorView.ja
to ElevatorView
va
ElevatorView
displays the elevator
simulation model.
add( personPanel, 0 );
} // end method personCreated
// invoked when Person has arrived at Elevator
public void personArrived( PersonMoveEvent personEvent )
{
// find Panel associated with Person that issued event
AnimatedPanel panel = getPersonPanel( personEvent );
if ( panel != null ) { // if Person exists
// Person stops at Floor Button
panel.setMoving( false );
panel.setAnimating( false );
panel.setCurrentFrame( 1 );
stopWalkingSound();
Invoked when Person
573
has arrived atLine
Elevator
Line 581
Find AnimatedPanel
associated with Line
Person
584that
issued event
Lines 589-592
Set Person’s AnimatedPanel to waiting state
(waiting for at Elevator)
double xPosition = PERSON_TO_BUTTON_DISTANCE ( panel.getSize().width / 2 );
double yPosition = panel.getPosition().getY();
panel.setPosition( xPosition, yPosition );
}
} // end method personArrived
 2003 Prentice Hall, Inc.
All rights reserved.
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
// invoked when Person has pressed Button
public void personPressedButton( PersonMoveEvent personEvent )
{
// find Panel associated with Person that issued event
AnimatedPanel panel = getPersonPanel( personEvent );
if ( panel != null ) { // if Person exists
// Person stops walking and presses Button
panel.setLoop( false );
panel.playAnimation( 1 );
panel.setVelocity( 0, 0 );
panel.setMoving( false );
panel.setAnimating( true );
stopWalkingSound();
}
} // end method personPressedButton
// invoked when Person has started to enter Elevator
public void personEntered( PersonMoveEvent personEvent )
{
// find Panel associated with Person that issued event
AnimatedPanel panel = getPersonPanel( personEvent );
Invoked when Person
Outline
is pressing Button
ElevatorView.ja
Find AnimatedPanel
va
associated withElevatorView
Person that
issued event
displays the elevator
simulation model.
Start animation of Person
pressing Button
Line 603
Line 606
Lines 611-612
Line 622
LinePerson
625
Invoked when
is entering Elevator
Find AnimatedPanel
associated with Person that
issued event
 2003 Prentice Hall, Inc.
All rights reserved.
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
if ( panel != null ) {
Outline
// determine velocity
double time = TIME_TO_ELEVATOR / ANIMATION_DELAY;
double distance =
elevatorPanel.getPosition().getX() panel.getPosition().getX() + 2 * OFFSET;
panel.setVelocity( distance / time, -1.5 );
// Person starts walking
panel.setMoving( true );
panel.playAnimation( 0 );
panel.setLoop( true );
ElevatorView.ja
va
ElevatorView
Determine Person’s velocity
displays the elevator
when entering Elevator, then
simulation model.
set Person’s AnimatedPanel to moving state
Lines 627-642
}
} // end method personEntered
// invoked when Person has departed from Elevator
public void personDeparted( PersonMoveEvent personEvent)
{
// find Panel associated with Person that issued event
AnimatedPanel panel = getPersonPanel( personEvent );
if ( panel != null ) { // if Person exists
Line 646
Line 649
Invoked when
Person
Line 657
has exited Elevator
Find AnimatedPanel
associated with Person that
issued event
// determine velocity (in opposite direction)
double time = TIME_TO_BUTTON / ANIMATION_DELAY;
double xVelocity = - PERSON_TO_BUTTON_DISTANCE / time;
panel.setVelocity( xVelocity, 0 );
Set Person velocity to
the opposite of that when
 2003
Prentice Hall, Inc.
the Person was
created
All rights reserved.
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
Outline
// remove Person from Elevator
elevatorPanel.remove( panel );
ElevatorView.ja
va
ElevatorView
displays the elevator
simulation model.
double xPosition =
PERSON_TO_ELEVATOR_DISTANCE + 3 * OFFSET;
double yPosition = 0;
String floorLocation =
personEvent.getLocation().getLocationName();
Lines 670-677
// determine Floor onto which Person exits
if ( floorLocation.equals( FIRST_FLOOR_NAME ) )
yPosition = firstFloorPosition +
( firstFloorPanel.getHeight() / 2 );
else
Set Person’s
to
Liney-coordinate
684
that of the Floor on which the
Elevator is located
if ( floorLocation.equals( SECOND_FLOOR_NAME ) )
yPosition = secondFloorPosition +
( secondFloorPanel.getHeight() / 2 );
yPosition -= panel.getHeight();
panel.setPosition( xPosition, yPosition );
// add Person to ElevatorView
add( panel, 0 );
Add Person’s AnimatedPanel
to ElevatorView
 2003 Prentice Hall, Inc.
All rights reserved.
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
// Person starts walking
panel.setMoving( true );
panel.setAnimating( true );
panel.playAnimation( 2 );
panel.setLoop( true );
walkClip.loop();
Outline
Set Person’s AnimatedPanel
to moving state
}
} // end method PersonDeparted
// invoked when Person has exited simulation
public void personExited( PersonMoveEvent personEvent)
{
// find Panel associated with Person that issued moveEvent
AnimatedPanel panel = getPersonPanel( personEvent );
if ( panel != null ) { // if Person exists
panel.setMoving( false );
panel.setAnimating( false );
// remove Person permanently and stop walking sound
synchronized( personAnimatedPanels )
{
personAnimatedPanels.remove( panel );
}
remove( panel );
stopWalkingSound();
ElevatorView.ja
va
ElevatorView
displays the elevator
simulation model.
Invoked when Person
has exited simulation
Lines 687-691
Line 696
Find Panel associated with
Person that issued moveEvent
Line 699
Line 709
Remove Person’s
AnimatedPanel
from ElevatorView
}
} // end method personExited
 2003 Prentice Hall, Inc.
All rights reserved.
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
// invoked when Door has opened in model
public void doorOpened( DoorEvent doorEvent )
{
// get DoorEvent Location
String location =
doorEvent.getLocation().getLocationName();
// play animation of Door opening
doorPanel.playAnimation( 0 );
doorPanel.setAnimationRate( 2 );
doorPanel.setDisplayLastFrame( true );
// play sound clip of Door opening
if ( doorOpenClip != null )
doorOpenClip.play();
Outline
Invoked when Door has opened
ElevatorView.ja
va
ElevatorView
displays the elevator
simulation
Play animation of Door
opening model.
Line 717
Lines 724-726
Play sound effect of Door opening
Lines 729-730
} // end method doorOpened
// invoked when Door has closed in model
public void doorClosed( DoorEvent doorEvent )
{
// get DoorEvent Location
String location =
doorEvent.getLocation().getLocationName();
// play animation of Door closing
doorPanel.playAnimation( 1 );
doorPanel.setAnimationRate( 2 );
doorPanel.setDisplayLastFrame( true );
Line 739
Invoked when Door has closed
Lines 742-744
Play animation of Door closing
 2003 Prentice Hall, Inc.
All rights reserved.
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
// play sound clip of Door closing
if ( doorCloseClip != null )
doorCloseClip.play();
} // end method doorClosed
// invoked when Button has been pressed in model
public void buttonPressed( ButtonEvent buttonEvent )
{
// get ButtonEvent Location
String location =
buttonEvent.getLocation().getLocationName();
Outline
Play sound effect of Door closing
ElevatorView.ja
va
ElevatorView
displays the elevator
Invoked when Button
simulation model.
has been pressed
// press Elevator Button if from Elevator
if ( location.equals( ELEVATOR_NAME ) ) {
elevatorButtonPanel.playAnimation( 0 );
elevatorButtonPanel.setDisplayLastFrame( true );
}
// press Floor Button if from Floor
else
if ( location.equals( FIRST_FLOOR_NAME ) ) {
firstFloorButtonPanel.playAnimation( 0 );
firstFloorButtonPanel.setDisplayLastFrame( true );
}
Lines 747-748
Obtain Location where
Button was
Linepressed
753
If Button was pressed in
Linesplay
756-757
Elevator,
animation of Elevator’s
Linespressed
760-763
Button being
Lines 768-771
If Button was pressed on
first Floor, play
animation of first Floor’s
Button being pressed
 2003 Prentice Hall, Inc.
All rights reserved.
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
Outline
else
if ( location.equals( SECOND_FLOOR_NAME ) ) {
secondFloorButtonPanel.playAnimation( 0 );
secondFloorButtonPanel.setDisplayLastFrame( true );
}
if ( buttonClip != null )
buttonClip.play(); // play button press sound clip
} // end method buttonPressed
// invoked when Button has been reset in model
public void buttonReset( ButtonEvent buttonEvent )
{
// get ButtonEvent Location
String location =
buttonEvent.getLocation().getLocationName();
ElevatorView.ja
va
If Button was pressed on
ElevatorView
second Floor, play
displays the elevator
animation of second Floor’s
simulation model.
Button being pressed
Lines 774-777
Invoked when Button
Line 785
has been reset
Lines 788-789
Obtain Location where
Button was reset
Lines 792-799
// reset Elevator Button if from Elevator
if ( location.equals( ELEVATOR_NAME ) ) {
// return to first frame if still animating
if ( elevatorButtonPanel.isAnimating() )
elevatorButtonPanel.setDisplayLastFrame( false );
else
elevatorButtonPanel.setCurrentFrame( 0 );
If Button was reset in
Elevator, play
animation of Elevator’s
Button being reset
}
 2003 Prentice Hall, Inc.
All rights reserved.
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
Outline
// reset Floor Button if from Floor
else
if ( location.equals( FIRST_FLOOR_NAME ) ) {
// return to first frame if still animating
if ( firstFloorButtonPanel.isAnimating() )
firstFloorButtonPanel.setDisplayLastFrame( false );
else
firstFloorButtonPanel.setCurrentFrame( 0 );
}
else
ElevatorView.ja
va
If Button
was reset on
ElevatorView
first Floor,
displaysplay
the elevator
animation of
first Floor’s
simulation
model.
Button being reset
Lines 804-812
Lines 815-823
if ( location.equals( SECOND_FLOOR_NAME ) ) {
// return to first frame if still animating
if ( secondFloorButtonPanel.isAnimating() )
secondFloorButtonPanel.setDisplayLastFrame(
false );
else
secondFloorButtonPanel.setCurrentFrame( 0 );
If Button was reset on
second Floor, play
animation of second Floor’s
Button being reset
}
} // end method buttonReset
 2003 Prentice Hall, Inc.
All rights reserved.
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
// invoked when Bell has rung in model
public void bellRang( BellEvent bellEvent )
{
bellPanel.playAnimation( 0 ); // animate Bell
if ( bellClip != null ) // play Bell sound clip
bellClip.play();
}
// invoked when Light turned on in model
public void lightTurnedOn( LightEvent lightEvent )
{
// turn on Light in Elevator
elevatorLightPanel.setCurrentFrame( 1 );
String location =
lightEvent.getLocation().getLocationName();
// turn on Light on either first or second Floor
if ( location.equals( FIRST_FLOOR_NAME ) )
firstFloorLightPanel.setCurrentFrame( 1 );
else
if ( location.equals( SECOND_FLOOR_NAME ) )
secondFloorLightPanel.setCurrentFrame( 1 );
} // end method lightTurnedOn
Outline
Invoked when Bell has rung
ElevatorView.ja
va
Play animation and sound
ElevatorView
effect of Bell ringing
displays the elevator
simulation model.
Invoked when Light
has turned
on 828
Line
Lines 830-833
If Light was
illuminated
Line
837
on first Floor, play
animation ofLines
first Floor’s
846-847
Light being turned on
Lines 851-852
If Light was illuminated on
second Floor, play animation
of second Floor’s Light
being turned on
 2003 Prentice Hall, Inc.
All rights reserved.
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
// invoked when Light turned off in model
public void lightTurnedOff( LightEvent lightEvent )
{
// turn off Light in Elevator
elevatorLightPanel.setCurrentFrame( 0 );
String location =
lightEvent.getLocation().getLocationName();
// turn off Light on either first or second Floor
if ( location.equals( FIRST_FLOOR_NAME ) )
firstFloorLightPanel.setCurrentFrame( 0 );
else
if ( location.equals( SECOND_FLOOR_NAME ) )
secondFloorLightPanel.setCurrentFrame( 0 );
} // end method lightTurnedOff
// return preferred size of ElevatorView
public Dimension getPreferredSize()
{
return new Dimension( VIEW_WIDTH, VIEW_HEIGHT );
}
Outline
Invoked when Light
has turned off
ElevatorView.ja
va
ElevatorView
If Light was turned off
displays the elevator
first Floor, play animation
simulation model.
of first Floor’s Light
being turned off
Line 857
Lines 866-867
If Light was turned off on
second Floor, play animation
Lines 871-872
of second Floor’s Light
being turned off
Lines 877-880
Set ElevatorView’s preferred
size to VIEW_WIDTH and
VIEW_HEIGHT
 2003 Prentice Hall, Inc.
All rights reserved.
882
883
884
885
886
887
888
889
890
891
892
893
// return minimum size of ElevatorView
public Dimension getMinimumSize()
{
return getPreferredSize();
}
// return maximum size of ElevatorView
public Dimension getMaximumSize()
{
return getPreferredSize();
}
}
Outline
ElevatorView.ja
Set ElevatorView’s
minimum
va sizes to
and maximum
VIEW_WIDTH andElevatorView
VIEW_HEIGHT
displays the elevator
simulation model.
Lines 883-892
 2003 Prentice Hall, Inc.
All rights reserved.
F.2 Class Objects
• ImagePanel
– Used for objects that are stationary in model
• e.g., Floor, ElevatorShaft
• MovingPanel
– Used for objects that “move” in model
• e.g., Elevator
• AnimatedPanel
– Used for objects that “animate” in model
• e.g., Person, Door, Button, Bell, Light
 2003 Prentice Hall, Inc. All rights reserved.
F.2 Class Objects (cont.)
The object (in model)
of Class...
Floor
is represented by the object
(in view)...
firstFloorPanel
secondFloorPanel
elevatorShaftPanel
elevatorPanel
firstFloorButtonPanel
secondFloorButtonPanel
elevatorButtonPanel
bellPanel
firstFloorLightPanel
secondFloorLightPanel
doorPanel
<not represented>
personAnimatedPanels
of Class...
ImagePanel
ImagePanel
ElevatorShaft
ImagePanel
Elevator
MovingPanel
AnimatedPanel
Button (on Floor)
AnimatedPanel
AnimatedPanel
Button (in Elevator)
Bell
AnimatedPanel
Light
AnimatedPanel
AnimatedPanel
AnimatedPanel
Door (in Elevator)
Door (on Floor)
<not represented>
Person
List (of
AnimatedPanels)
Fig. F.2 Objects in the ElevatorView representing objects in the model.
 2003 Prentice Hall, Inc. All rights reserved.
F.2 Class Objects (cont.)
The object (in
is represented by the object of Class...
model) of
(in view)...
Class...
AnimatedPanel
<not represented> elevatorLightPanel
ImagePanel
<not represented> ceilingPanel
ImagePanel
<not represented> wallPanel
Fig. F.3 Objects in the ElevatorView not represented in the model.
 2003 Prentice Hall, Inc. All rights reserved.
F.3 Class Constants
• Constants specify such information as:
–
–
–
–
–
Initial placement of objects in ElevatorView
Rate at which ElevatorView redraws screen
Names of image files used by ImagePanels
Names of sound files used by SoundEffects
Distances in pixels the ImagePanels representing
Elevator and Person must travel
– Times needed to travel these distances
 2003 Prentice Hall, Inc. All rights reserved.
F.4 Class Constructor
• ElevatorView constructor’s responsibilities:
–
–
–
–
–
Instantiate ImagePanels
Add all ImagePanels to ElevatorView
Initialize audio objects
Compute initial velocity and distance traveled
Start animation Timer
 2003 Prentice Hall, Inc. All rights reserved.
F.4 Class Constructor (cont.)
firstFloorButtonPanel : AnimatedPanel
firstFloorPanel : ImagePanel
secondFloorButtonPanel : AnimatedPanel
secondFloorPanel : ImagePanel
firstFloorLightPanel : AnimatedPanel
elevatorShaftPanel : ImagePanel
secondFloorLightPanel : AnimatedPanel
ceilingPanel : ImagePanel
wallPanel : ImagePanel
elevatorPanel : MovingPanel
: ElevatorView
bellClip : AudioClip
doorOpenClip : AudioClip
lightPanel : AnimatedPanel
doorCloseClip : AudioClip
: SoundEffects
bellPanel : AnimatedPanel
doorPanel : AnimatedPanel
elevatorButtonPanel : AnimatedPanel
elevatorClip : AudioClip
buttonClip : AudioClip
walkClip : AudioClip
Fig F.4 Object diagram for the ElevatorView after initialization.
 2003 Prentice Hall, Inc. All rights reserved.
F.5 Event Handling
• Event Handling in the view
– ElevatorView implements interface ElevatorSimulationListener
• ElevatorView implements all interfaces
– ElevatorSimulation sends events to
ElevatorView
• ElevatorCaseStudy registers ElevatorView for
events from ElevatorSimulation
 2003 Prentice Hall, Inc. All rights reserved.
F.5.1 ElevatorMoveEvent types
• ElevatorSimulation
– Sends ElevatorMoveEvent when Elevator departed
or arrived in the model
– Invokes method elevatorDeparted when Elevator
departed from Floor
– Invokes method elevatorArrived when Elevator
arrived at Floor
 2003 Prentice Hall, Inc. All rights reserved.
F.5.2 PersonMoveEvent types
• ElevatorSimulation
– Sends PersonMoveEvent when Person performes actions
– Invokes method personCreated when model instantiates new
Person
– Invokes method personArrived when Person arrives at
Elevator
– Invokes method personPressedButton when Person presses
Button
– Invokes method personEntered when Person enters
Elevator
– Invokes method personDeparted when Person exits
Elevator
– Invokes method personExited when Person exits simulation
 2003 Prentice Hall, Inc. All rights reserved.
F.5.3 DoorEvent types
• ElevatorSimulation
– Sends DoorEvent when Door opened or closed in the
model
– Invokes method doorOpened when Door opened
– Invokes method doorClosed when Door closed
 2003 Prentice Hall, Inc. All rights reserved.
F.5.4 ButtonEvent types
• ElevatorSimulation
– Sends ButtonEvent when Button pressed or reset in
the model
– Invokes method buttonPressed when Button pressed
– Invokes method buttonReset when Button reset
 2003 Prentice Hall, Inc. All rights reserved.
F.5.5 BellEvent types
• ElevatorSimulation
– Sends BellEvent when Bell rung
• Invoking method bellRang
 2003 Prentice Hall, Inc. All rights reserved.
F.5.6 LightEvent types
• ElevatorSimulation
– Sends LightEvent when Light changed state in the
model
– Invokes method lightTurnedOn when Light turned on
– Invokes method lightTurnedOff when Light turned
off
 2003 Prentice Hall, Inc. All rights reserved.
F.6 Artifacts Revisited
• Component Diagram for view
– Package view contains six artifacts
• ElevatorView.java
– Aggregates (imports) packages images, sounds,
events
• ImagePanel.java
• MovingPanel.java
• AnimatedPanel.java
• ElevatorMusic.java
• SoundEffects.java
 2003 Prentice Hall, Inc. All rights reserved.
F.6 Component Diagrams Revisited (cont.)
view
<<imports>>
<<file>>
<<imports>>
ElevatorView.java
<<imports>>
<<file>>
<<file>>
ImagePanel.java
MovingPanel.java
<<file>>
<<file>>
AnimatedPanel.java
images
SoundEffects.java
sounds
1
event
1
1
Fig F.5 Component diagram for package view.
 2003 Prentice Hall, Inc. All rights reserved.
F.7 Conclusion
• OOD/UML case study
– Implement object-oriented system designs generated by
UML
– Using Java GUI, graphics and sound capabilities
 2003 Prentice Hall, Inc. All rights reserved.