Greenfoot Virtual Xylophone


(Click here for working example)

This xylphone project uses sampled .wav sounds from an Alto Orff Xylophone. Your could create this project using MIDI sounds - but that is for another day.

1. Download and Unzip the "XylophoneProjectBase" file.

Download "XylophoneProjectBase" (in zip format)

This file has the graphics, sound clips, and World setup for the project. Save the project into your file area. Open, and click "Compile all" to see the xyophone base.

2. Double click "xylophoneWorld" and look at the following code:
(You do not need to type this in.)

Note that the "xylophoneWorld" script has been written for you. The code defines a "Bar" class and 8 subclasses of "Bar" for each pitch on the xylophone. The code also puts the eight bars into the xylophone World and assignes them the proper starting images.

3. This project has two building steps

  1. Write the general code for the "Bar" class that creates the methods for playing the sound and changing the costume.
  2. Writing the code for each subclass bar that sets the specific files for the pitch sound and graphics.

4. First - the code for the Bar. Double click the "Bar" and add start with declaring Strings for "Note", "Up", "Pressed", and "Key".

5. Now type the following to define the method that plays the pitch and changes the image of the bars when clicked. This script also allows the Bars to play when one of the keys are pressed on the computer keyboard.

6. Click "Compile All." The xylophone still won't play, but this will check for errors.

7. Click on the "LowC" Bar. Add the following Code to "LowC." Notice how the first step is to give values to the 4 variables "Note", "Up", "Pressed", and "Key."

8. For each of the other 7 bars, add the following Codes:

9. Click "Compile All" and test your xylophone.


1. Record 8 new .wav files and put them in the sounds folder of your xylophone scenario. Reassign the sounds to create a new instrument.

2. Create a way to "Take Bars Off" to create a Pentatonic Scale.

Email Mr.Michaud

Copyright ©2011 Mr. Michaud.