-
Notifications
You must be signed in to change notification settings - Fork 0
/
Button.java
33 lines (29 loc) · 994 Bytes
/
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
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
public class Button extends Actor
{
// Setup action Variable
private String action;
public Button(String buttonText, String actionPar) {
// Set action Variable
action = actionPar;
// Create Image based on Text
GreenfootImage buttonImage = new GreenfootImage(buttonText, 24, new Color(255, 255, 255), new Color(0, 0, 0), new Color(128, 128, 128));
setImage(buttonImage);
}
public void act()
{
Board board = (Board) getWorld();
// Check if mouse clicked Button
if (Greenfoot.mouseClicked(this)) {
// Call Method based on action Variable
switch(action){
case "start":
board.startGame();
break;
case "restart":
board.restartGame();
break;
}
}
}
}