Hello there! I'm trying to create a media player and I'm having some difficultly. I'm been playing around with it for hours now and I just need some other eyes other then mines. Any help is appreciated!
public class MyWorld extends World
{
private GreenfootSound sound = new GreenfootSound("win.mp3");
private volUp volumeUp = new volUp();
private volDown volumeDown = new volDown();
private int volumeLevel = 50;
/**
* Constructor for objects of class MyWorld.
*
*/
public MyWorld()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(600, 400, 1);
addObject(new Start(),300, 200);
addObject(new volUp(),500, 300);
addObject(new volDown(),500, 350);
}
public volUp getVolUp()
{
return volumeUp ;
}
public volDown getVolDown()
{
return volumeDown;
}
public void setVolumeLevel(int volumeLevel)
{
this.volumeLevel = volumeLevel;
}
public GreenfootSound getSound()
{
return sound;
}
}public class volDown extends Start
{
GreenfootSound sound;
int volume = 100;
/**
* Act - do whatever the volDown wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
if (Greenfoot.mouseClicked(((MyWorld)getWorld()).getVolDown())){
setImage("volDown.png");
MyWorld myWorld = (MyWorld)this.getWorld();
GreenfootSound mySound = myWorld.getSound();
volume -=10;
if(volume<0)
{
volume=0;
}
mySound.setVolume(volume);
}
}
}
