Computer Science II, Lab 07
Tuesday, October 2nd
Objectives:
- Experience with Event-Driven Programming and Swing elements.
- Explore Panels
Introduction
For this Lab, you will be working with CannonWorld.
You will make a series of fairly small changes that are designed to give you
some experience working with basic Swing elements and event
driving programming.
For the most part, these activities should be able to be completed in any
order. Thus, if you read one activity and are unclear how to complete it,
you may find it easier to move on to another activity and come back later.
Begin by downloading and unzipping the following file:
Activity A : Limiting the number of shots
- Modify the CannonWorld so that the user is restricted to six shots.
- Add another "message" (using drawString() ) to the Game that displays the number of shots that
have been fired so far.
- If the user tries to fire again after six shots, the label should display a
“Sorry...” message.
Activity B : Reversing the direction of the slider
- Change the current Angle-slider so that moving it down changes the angle
to smaller values rather than larger ones.
Activity C : Adding another Button
- Add a second button (using JButton) to the left side of the CannonWorld
(the west)
- This Button should be labeled "Pause."
- Pressing this button when the CannonBall is in the air should cause the
CannonBall to "pause" mid flight and appear to hover there until the button
is pressed again.
- [Note, this button may end up covering the cannon. You are not
required to fix this problem].
Activity D : You call it...
Add another button or scrollbar (or another element of your choice) to the
bottom of the screen. What this does is totally up to you.
EXPLORE!
Deliverables
Use the homework submission system. Under the link for Lab07, upload
the following code:
Also, please submit a paper printout of this class!