-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathButton.java
More file actions
36 lines (30 loc) · 873 Bytes
/
Button.java
File metadata and controls
36 lines (30 loc) · 873 Bytes
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
import greenfoot.*; // import every greefoot function, object and more
public class Button extends Actor
{
private String action; // which action should this button has
public Button(String _action)
{
this.action = _action;
this.setImage(this.getButtonImage());
}
public void act()
{
this.executeButtonAction();
}
/**
* Execute the action of the given button
*/
private void executeButtonAction() {
if (!Greenfoot.mouseClicked(this)) return;
if (this.action == "start") {
GameManager.start(); // start game
return;
}
}
/**
* Set the image of the button based on the action
*/
private GreenfootImage getButtonImage() {
return new GreenfootImage("./images/" + this.action + "_button.png");
}
}