This site requires JavaScript, please enable it in your browser!
Greenfoot back
fred
fred wrote ...

2012/5/22

<Identifier> expected

fred fred

2012/5/22

#
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. */ String tastenliste; tastenliste={"a","s","d","f","g","j","k"}; Stringsoundliste; soundliste={"2a.wav","2b.wav","2c.wav","2d.wav","2e.wav","2f.wav","2g.wav"} public Piano() { super(800, 340, 1); int i; i=0; while(i<10) { Key Taste; Taste=new Key(tastemnliste",soundliste); addObject (Taste, i*Taste.getImage().getWidth()+50,(Taste.getImage().getHeight()))*0,5; i= i+1; } } }
nccb nccb

2012/5/22

#
For member variables like tastenliste, you must initialise them on the same line as they are declared. You are putting code directly into the class body, which is not allowed. So change this:
    String[] tastenliste;
    tastenliste={"a","s","d","f","g","j","k"};
    String[]soundliste;
    soundliste={"2a.wav","2b.wav","2c.wav","2d.wav","2e.wav","2f.wav","2g.wav"}
to:
    String[] tastenliste ={"a","s","d","f","g","j","k"};
    String[]soundliste = {"2a.wav","2b.wav","2c.wav","2d.wav","2e.wav","2f.wav","2g.wav"};
Also: your code had a missing semi-colon, and you are using comma as a decimal seperator near the end. Java uses dot instead, so use "0.5" not "0,5". And your bracketing is wrong on that same line:
addObject (Taste, i*Taste.getImage().getWidth()+50,(Taste.getImage().getHeight()))*0,5;
should be:
addObject (Taste, i*Taste.getImage().getWidth()+50,Taste.getImage().getHeight() *0.5);
Notice the 0.5 should be inside the bracket. And a couple more: you have an extra quote and a typo in the line creating a new key:
Taste=new Key(tastemnliste[i]",soundliste[i]);
should be:
Taste=new Key(tastenliste[i],soundliste[i]);
fred fred

2012/5/23

#
Thank you :)
You need to login to post a reply.