forked from RalfsGames/antGreenfoot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CounterTime.java
38 lines (31 loc) · 796 Bytes
/
CounterTime.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
import greenfoot.GreenfootImage;
/**
* Created by Vincent Modrow on 26/02/2017.
* PACKAGE_NAME
*/
public class CounterTime extends Counter {
private double value = 0;
private String text;
public CounterTime() {
this("");
}
public CounterTime(String prefix) {
text = prefix;
int imageWidth = (text.length() + 2) * 50;
setImage(new GreenfootImage(imageWidth, 16));
updateImage();
}
/**
* Show the current text and count on this actor's image.
*/
private void updateImage() {
GreenfootImage image = getImage();
image.clear();
image.drawString(text + Double.toString(value), 1, 12);
}
@Override
public void increment() {
value += 1;
updateImage();
}
}