I want that every time when the run button is pressed that the music starts and every time when the run botton its paused that the music stop.
PLEASE HELP!


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.lang.Object; import java.util.List; /** * Write a description of class Schlachtfeld here. * * @author (your name) * @version (a version number or a date) */ public class Schlachtfeld extends World { static GreenfootSound backGroundMusic = new GreenfootSound( "MarioThemeAcapella.mp3" ); public static void startMusic() { if (!backGroundMusic.isPlaying()) { backGroundMusic.play(); } } public static void stopMusic() { backGroundMusic.stop(); } public void act() { startMusic(); if (Greenfoot.isKeyDown( "e" )) for (Object obj : getObjects(Bomb. class )) ((Bomb) obj).explode(); if (Greenfoot.isKeyDown( "m" )) for (Object obj : getObjects(Bomb2. class )) ((Bomb2) obj).explode2(); if (getObjects(Bomber1. class ).isEmpty() && !getObjects(Bomber2. class ).isEmpty()) { winnerLuigi(); stopMusic(); } if (!getObjects(Bomber1. class ).isEmpty() && getObjects(Bomber2. class ).isEmpty()) { winnerMario(); stopMusic(); } } public void winnerMario() { List objekte = getObjects( null ); removeObjects(objekte); setBackground( "winnerMario.jpg" ); } public void winnerLuigi() { List objekte = getObjects( null ); removeObjects(objekte); setBackground( "winnerLuigi.jpg" ); } /** * Constructor for objects of class Schlachtfeld. * */ public Schlachtfeld() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super ( 15 , 9 , 60 ); prepare(); } it doesnt work i want that it stops when someone wins ???? |