I have finished chapter 5 of the greenfoot book. I want to add text to the keys of the piano, that says which note they play. Does anybody know how to do this?
getImage().setColor(new Color(255, 0, 0));
getImage().setFont(new Font("Arial", Font.BOLD, 18));
getImage().drawString(key,23,15);import greenfoot.*; // (World, Actor, GreenfootImage, and Greenfoot)
import java.awt.Color;
/**
* A piano that can be played with the computer keyboard.
*/
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#" };
private String[] keyNotes =
{ "2c", "2d", "2e", "2f", "2g", "2a", "2b", "3c", "3d", "3e", "3f", "3g" };
/**
* Make the piano. This means mostly, apart from defining the size,
* making the keys and placing them into the world.
*/
public Piano()
{
super(800, 340, 1);
makeKeys();
showMessage();
}
/**
* Create the piano keys and place them in the world.
*/
public void makeKeys()
{
for (int i = 0; i < whiteKeys.length; i++)
{
Key key = new Key(whiteKeys[i], whiteNotes[i] + ".wav", "white-key.png" , "white-key-down.png");
addObject(key, 54 + (i*63), 140);
GreenfootImage bg = getBackground();
bg.setColor(Color.BLACK);
bg.drawString(keyNotes[i], 23, 15);
}private void makeKeys()
{
for(int i = 0; i < whiteKeys.length; i++) {
Key key = new Key(whiteKeys[i], whiteNotes[i]+".wav", "white-key.png", "white-key-down.png");
addObject(key, 54 + (i*63), 140);
key.getImage().setColor(new Color(255, 0, 0));
key.getImage().setFont(new Font("Arial", Font.BOLD, 18));
key.getImage().drawString(whiteNotes[i],15,200);
}