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

2014/9/11

Problem with button for soundboard

mobileash66 mobileash66

2014/9/11

#
So I've created this, but the public button part gets an error saying "invalid method declaration; return type required" but a semi-colon can't go there? This code is linked to my World code which is placed beneath this section of code. Plus the bit where I'm getting the error was suggested by an friend but I can't contact him for a while. I really don't know what it does that much.
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Clickable button that plays a sound
 * 
 * @author (mobileash66) 
 * @version (v0.2)
 */
public class button extends Actor
{
private boolean isDown;
private String button;
private String sound;

    /**
     * Creates a new button.
     */ 
    public Button(String buttonName, String soundFile)
    {
        button = buttonName;
        sound = soundFile;
    }


    public void act() 
    {
                if ( !isDown && Greenfoot.isKeyDown(button) ) {            
            setImage ("bass2.png");
            isDown = true;
            play();
    }
    if ( isDown && !Greenfoot.isKeyDown(button) ) {            
            setImage ("bass1.png");
            isDown = false;        
    }
    }    
    public void play() {
    Greenfoot.playSound(sound);
}
}
World Code:
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class background here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class background extends World
{
private String[] bassButtons = {"a","S","d","f","g","h","j","k","l",";","'","\\"};
private String [] bassSounds = {"3c","3d","3e","3f","3g","3a","3b","4c","4d","4e","4f","4g"};
//private Button textButton=null;
    /**
     * Constructor for objects of class background.
     * 
     */
    public background()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(600, 400, 1); 
        bassButtons();
        // creating the button  
        //textButton= new Button("Click here to run method");  
        //addObject(textButton, 500, 30);  
        // in the act to catch button click  
        //if (Greenfoot.mouseClicked(textButton)) new GreenfootSound(/* sound filename */).play();
    }
private void bassButtons()
{ 
int i = 0;
while (i < bassButtons.length) {
Button button = new button (bassButtons[i], bassSounds[i]+".wav");
addObject(button,i*button.getImage().getWidth() + 54,140);
i++;
}
}             
}
lordhershey lordhershey

2014/9/11

#
Your class is 'button' where the constructor is 'Button' the case has to match. It things you are declaring a method called 'Button'
You need to login to post a reply.