import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;
import java.awt.Font;
import greenfoot.GreenfootSound;
import greenfoot.GreenfootImage;
public class PlayMusicButton extends Actor
{
private static final int WIDTH = 100;
private static final int HEIGHT = 40;
private static final Color BACKGROUND =
new Color(0, 0, 0);
private static final float FONT_SIZE = 20.0F;
public void act()
{
checkMouseClick();
}
private void makeIamge()
{
GreenfootImage image = new GreenfootImage(this.WIDTH, this.HEIGHT);
image.fillRect(0, 0, this.WIDTH, this.HEIGHT);
image.setColor(Color.BLACK);
image.drawRect(0, 0,WIDTH, 1,HEIGHT,1);
image.setColor(Color.BLACK);
Font font = image.getFont();
if (playing) {
font = font.deriveFont(1);
} else {
font = font.deriveFont(0);
}
image.setFont(font);
image.drawString(this.text, 5, 15);
setImage(image);
}
public PlayMusicButton(String text, Color c)
{
this.text = text;
this.color = c;
this.WIDTH = 100;
this.HEIGHT = 25;
makeImage(false);
this.sound = new GreenfootSound(text + ".mp3");
}
private void checkMouseClick()
{
if (Greenfoot.mouseClicked(this)) {
if (this.sound.isPlaying())
{
this.sound.stop();
makeIamge(false);
}
else
{
PlayerWorld player = (PlayerWorld)getWorld();
player.stop();
makeImage(true);
this.sound.play();
}
}
}
public boolean stop()
{
if (this.sound.isPlaying())
{
this.sound.stop();
makeIamge (false);
return true;
}
return false;
}
}
