-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCycleButton.java
More file actions
executable file
·47 lines (42 loc) · 1.33 KB
/
CycleButton.java
File metadata and controls
executable file
·47 lines (42 loc) · 1.33 KB
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
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class CycleButton here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class CycleButton extends Button {
/**
* Act - do whatever the CycleButton wants to do. This method is called whenever the 'Act' or
* 'Run' button gets pressed in the environment.
*/
int numOfCycles = 5; // 5, 10, 15
boolean ifDiscbetion = true;
private GreenfootImage unclickedCycleButton =
new GreenfootImage("button/cycleButton_unpressed_5.png");
private GreenfootImage clickedCycleButton =
new GreenfootImage("button/cycleButton_pressed_5.png");
public CycleButton() {
super(true);
}
public void act() {
if (Greenfoot.mouseClicked(this)) {
if (numOfCycles < 15) {
numOfCycles += 5;
} else {
numOfCycles = 5;
}
clickedCycleButton = new GreenfootImage("button/cycleButton_pressed_" + numOfCycles + ".png");
clickedCycleButton.scale(400, 120);
setImage(clickedCycleButton);
} else {
unclickedCycleButton =
new GreenfootImage("button/cycleButton_unpressed_" + numOfCycles + ".png");
unclickedCycleButton.scale(400, 120);
setImage(unclickedCycleButton);
}
}
public int getCycle() {
return numOfCycles;
}
}