0% found this document useful (0 votes)
14 views2 pages

JF 2 11 Practice

Uploaded by

akhilaakula53
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views2 pages

JF 2 11 Practice

Uploaded by

akhilaakula53
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

academy.oracle.

com

Java Fundamentals
2-11: Keyboard Controls
Practice Activities

Lesson Objectives:
• Use keyboard controls to manipulate an animation

Vocabulary:
Identify the vocabulary word for each definition below.

Allow the user to control one or more objects with the keyboard keys while the animation
is running.

Any action initiated by the user that is designed to influence the program’s execution
during play.

Listen for, and react to, a keyboard keystroke that you specify.

The act of coding events to handle each procedure.

Procedures in the Scene class that listen for keyboard input while the animation is
running.

Try It/Solve It:


Open the "WhiteRabbitProject" project you saved in the previous lesson. You will use this project for all of the practice
activities listed below.

1. Access event listeners.


a. View the event listeners available in the scene.

2. Add and program a key press event listener.


a. Add a key press listener to the WhiteRabbitProject.
b. Program the KeyPressListener procedure so that the baby bunny hops one time when the "H" key is
pressed on the keyboard. TIP: Use the bipedHop procedure.
c. Test the key press listener.
d. Save the project.

Copyright © 2019, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their
respective owners.
2

3. Program additional motions.


a. Add two or three more hedges in various places to the WhiteRabbitProject scene to be used as obstacles
for the bunny.
b. Program an additional motion so that the bunny turns a quarter turn to the right when the "R" keyboard
key is pressed.
c. Program another motion so that the bunny turns a quarter turn to the left when the "L" keyboard key is
pressed.
d. Test the animation and use the keyboard keys to move the bunny around the scene, avoiding the wall,
white rabbit, and hedges.
e. Save the project.

4. Save your biped class so that you can use the hop procedure in other animations.
a. Click on the classes list button and choose Biped and then biped again.
b. Save the biped class to your MyClasses directory using the Save to class file button
c. Save the project.

5. Create a new animation from the starters tab on the new menu. Choose the far East template and add the
MarchHare into the left side of your scenario facing to the right across the screen..
a. Using the classes list button and the biped class add your saved biped class to your new project.
b. Make the MarchHare hop across the screen six times.
c. Save your project as EastMarchHare.

Optional Activities:
Complete the following optional practice activities below to continue practicing the concepts you learned in this lesson.

1. Create a new project using the sea floor template. Set up an initial scene for a treasure hunt. Add a submarine,
dolphins, and several fish. Add coral, seaweed, and sea plants. Add a treasure chest and put a hidden object inside
of it.
a. Program the submarine to move forward, backward, up, down, left and right using keyboard keys and
arrow keys.
b. Using an IF statement, program the treasure chest lid to open and reveal the hidden object if the
submarine collides with the treasure chest.
c. Save the project.

2. Create a new project using the snow template. Create a hiking scene with a person object riding a snow yak through
snowy mountains to a base camp. The base camp needs a few items that the snow yak will bring. Put other objects
on the snow yak that it should carry to the people at the base camp. The base camp has people, tents, prayer flags,
and other camping objects.
a. Program the snow yak to move forward, backward, left and right using the arrow keys on your keyboard.
b. Program the snow yak to say something when the Z key is pressed (browse the internet to research what
noises snow yaks make).
c. If the snow yak collides with the tent at base camp, program the people at the base camp to cheer for the
snow yak’s arrival.

Copyright © 2019, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their
respective owners.

You might also like