Hi! I hope you are all enjoying the summer so far. I am working on the piano scenario. I am having issues with the black keys. I went to the book scenarios and opened the folder "piano-complete". If you look at that scenario, you will see that there is no class called "black keys". Is this how I am supposed to do this? I was wondering if you need the "black keys" class in order to make black keys on the piano. Right now, I have the white keys in the right place. For the black keys, I have the keys in the right place, but each key appears a white key, not a black key. So all I need to do now is to fix the image of those keys as black keys, not white keys. But I don't know how to do that.
import greenfoot.*; // (World, Actor, GreenfootImage, and Greenfoot)
import java.awt.Color;
/**
* A piano that can be played with the computer keyboard.
*
* @author: M. Kolling
* @version: 0.1
*/
public class Piano extends World
{
private String[] whiteKeys =
{ "a", "s", "d", "f", "g", "h", "j", "k", "l", ";", ":", "]" };
private String[] whiteNotes =
{ "2c", "2d", "2e", "2f", "2g", "2a", "2b", "3c", "3d", "3e", "3f", "3g" };
private String[] blackKeys =
{ "w", "e", "", "t", "y", "u", "", "o", "p", "", "[" };
private String[] blackNotes =
{ "2c#", "2d#", "", "2f#", "2g#", "2a#", "", "3c#", "3d#", "", "3f#" };
/**
* Make the piano.
* This adds 12 white piano keys to the world.
*/
public Piano()
{
super(800, 340, 1);
makeKeys();
showMessage();
}
/**
* Create the piano keys and place them in the world.
*/
private void makeKeys()
{
for(int i = 0; i < whiteKeys.length; i++) {
Key key = new Key(whiteKeys[i], whiteNotes[i] +".wav");
addObject (key, i*63 + 54, 140);
}
for(int i = 0; i < whiteKeys.length-1; i++) {
if( ! blackKeys[i].equals("") ) {
Key key = new Key(blackKeys[i], blackNotes[i] +".wav");
addObject(key, 85 + (i*63), 86);
}
}
}
public void showMessage()
{
GreenfootImage bg = getBackground();
bg.setColor(Color.WHITE);
bg.drawString("Click 'Run', then use your keyboard to play", 25, 320);
}
}