-
Notifications
You must be signed in to change notification settings - Fork 1
/
Button.java
40 lines (37 loc) · 1.27 KB
/
Button.java
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
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Button here.
*
* @author (your name)
* @version (a version number or a date)
*/
public abstract class Button extends Actor
{
/**
* Act - do whatever the Buttons wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act(String buttonName)
{
GreenfootSound push = new GreenfootSound("Button.mp3");
push.setVolume(50);
if (Greenfoot.mouseMoved(this)) {
setImage(buttonName + "_Over.png");
} else if (Greenfoot.mouseMoved(null)) {
setImage(buttonName + ".png");
}
if (Greenfoot.mousePressed(this)) {
getImage().scale((int)Math.round(getImage().getWidth() * 0.9), (int)Math.round(getImage().getHeight() * 0.9));
}
if (Greenfoot.mouseClicked(null) || Greenfoot.mouseDragEnded(null)) {
setImage(buttonName + ".png");
}
if (Greenfoot.mouseClicked(this)) {
setImage(buttonName + ".png");
push.play();
Greenfoot.delay(5);
onButtonClicked();
}
}
public abstract void onButtonClicked();
}