import greenfoot.*; // (World, Actor, GreenfootImage, and Greenfoot) /** * A piano that can be played with the computer keyboard. * * @author: M. Kolling * @version: 0.1 */ public class Piano extends World { /** * Make the piano. */ private String[] whitekeys = {"q", "w", "e", "r", "t", "y", "u", "i", "o", "p", "[", "]"}; private String[] whiteNotes = {"2c", "2d", "2e", "2f", "2g", "2a", "2b", "3c", "3d", "3e", "3f", "3g"}; public Piano() { super(800, 340, 1); makekeys(); } /** * This puts all of the keys where they should go. */ public void makekeys() { int i = 0; while (i < 12) { Key whiteKeys = new Key(whiteKeys[i], whiteNotes[i] + ".wav"); int keyWidth = myKey.getImage().getWidth(); int keyHeight = myKey.getImage().getHeight(); int worldWidth = getWidth(); addObject(myKey, i*keyWidth + (((worldWidth - (keyWidth * 12))/2) + (keyWidth / 2)), keyHeight / 2); i = i + 1; } } }