So i was making the piano from the book scenarios (class project) and when i got it just about done, it wont compile.. what am i doing wrong?
piano class
import greenfoot.*; // (World, Actor, GreenfootImage, and Greenfoot)
public class Key extends Actor
{
private boolean isDown;
private String key;
private String sound;
private String keyDown;
private String keyUp;
/**
* Create a new key linked to a keyboard key
*/
public Key(String keyName, String soundFile, String Img1, String Img2)
{
key = keyName;
sound = soundFile;
keyDown = Img1;
keyUp = Img2;
setImage(keyUp);
}
/**
* Do the action for this key.
*/
public void act()
{
if ( !isDown && Greenfoot.isKeyDown(key)) {
setImage(keyDown);
playSound();
isDown = true;
}
if ( isDown && !Greenfoot.isKeyDown(key)) {
setImage (keyUp);
isDown = false;
}
}
/**
* play a key
*/
public void playSound()
{
Greenfoot.playSound(sound);
}
}import greenfoot.*; // (World, Actor, GreenfootImage, and Greenfoot)
/**
* A piano that can be played with the computer keyboard.
*
* @author: Kyle Strauser
* @version: 0.1
*/
import greenfoot.*;
import java.awt.Color;
public class Piano extends World
{
private String[] whiteKeys =
{"a", "s", "d", "f", "g", "h", "j", "k", "l", ";", "'", "\\" };
private String[] whiteNotes =
{"3c", "3d", "3e", "3f", "3g", "3a", "3b", "4c", "4d", "4e", "4f", "4g"};
private String[] blackKeys =
{ "W", "E", "", "T", "Y", "U", "", "O", "P", "", "]" };
private String[] blackNotes =
{ "3c#", "3d#", "", "3f#", "3g#", "3a#", "", "4c#", "4d#", "", "4f#" };
/**
* Make the piano.
*/
public Piano()
{
super(800, 340, 1);
makeKeys();
makeBlackKeys();
}
/**
* make the piano keys
*/
public void makeKeys()
{
//white keys
int i = 0;
while (i < whiteKeys.length) {
Key key = new Key(whiteKeys[i], whiteNotes[i] + ".wav", "white-key-down.png", "white-key.png");
addObject(key, i * 63 + 54, 140);
i = i + 1;
}
}
/**
* make the black keys bro
*/
public void makeBlackKeys()
{
int i = 0;
while (i < blackKeys.length) {
if (! "".equals(blackKeys[i])) {
Key key = new Key(blackKeys[i], blackNotes[i] + ".wav", "black-key-down.png", "black-key.png");
addObject(key, i * 63 + 86, 80);
}
}
i = i + 1;
}
}
