How do i do this? Please help me ;
Add two buttons to change voume up and down
Requirement:
• there should be no static data used in any of the classes in your homework.
• all data in all classes must be private.
• if you declare an reference object, this object must be initialized with a new statement.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class MyWorld here. * * @author (your name) * @version (a version number or a date) */ public class MyWorld extends World { /** * 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 Music(),100,200); addObject(new MusicUp(),380,300); addObject(new MusicDown(),550,300); } }
//music class import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Music here. * * @author (your name) * @version (a version number or a date) */ public class Music extends Actor { private GreenfootSound sound; public Music(){//constructor sound= new GreenfootSound("music.mp3"); } /** * Act - do whatever the Music wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { if (Greenfoot.mouseClicked(this)) { //this is for music to play if(sound.isPlaying()){//bollean type to stop music sound.pause(); setImage("pause.png"); } else{ sound.play(); setImage("play.png"); } //end of the music play } } }
//Music Down import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class MusicDown here. * * @author (your name) * @version (a version number or a date) */ public class MusicDown extends Actor { /** * Act - do whatever the MusicDown wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { // Add your action code here. } }
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class MusicUp here. * * @author (your name) * @version (a version number or a date) */ public class MusicUp extends Actor { /** * Act - do whatever the MusicUp wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { // Add your action code here. } }