I am trying to use the "setVouume()" to control the volume but it not work. I cannot find out the problem.
Could anyone teach me? Thank you.
This is VolumeUp class
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Start here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Start extends Actor
{
private GreenfootSound mySound = new GreenfootSound("Twice - I CAN'T STOP ME.mp3");
private int volumeA = 50;
public Start()
{
}
public Start(GreenfootSound mySound, int volumeA)
{
this.mySound = mySound;
this.volumeA = volumeA;
}
public GreenfootSound getMySound()
{
return mySound;
}
public int getVolumeA()
{
return volumeA;
}
public void setMySound(GreenfootSound mySound)
{
this.mySound = mySound;
}
public void setVolumeA(int volumeA)
{
this.volumeA = volumeA;
}
/**
* Act - do whatever the Start wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
startButton();
curVolume();
}
public void startButton()
{
if(Greenfoot.mouseClicked(this))
{
if(!(mySound.isPlaying()))
{
mySound.play();
setImage("stop.png");
}
else
{
mySound.pause();
setImage("start.png");
}
}
}
public void curVolume()
{
mySound.setVolume(volumeA);
}
public void volUp()
{
if(volumeA < 100)
{
volumeA = volumeA + 5;
curVolume();
}
}
public void volDown()
{
if(volumeA > 0)
{
volumeA = volumeA - 5;
mySound.setVolume(volumeA);
}
}
}
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class VolumeUp here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class VolumeUp extends Start
{
public VolumeUp()
{
}
/**
* Act - do whatever the VolumeUp wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
up();
}
public void up()
{
if(Greenfoot.mouseClicked(this))
{
Start start = new Start();
start.volUp();
}
}
}
