-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLabel.java
executable file
·76 lines (67 loc) · 1.92 KB
/
Label.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* A Label class that allows you to display a textual value on screen.
*
* <p>The Label is an actor, so you will need to create it, and then add it to the world in
* Greenfoot. If you keep a reference to the Label then you can change the text it displays.
*
* @author Amjad Altadmri
* @version 1.1
*/
public class Label extends Actor {
private String value;
private int fontSize;
private Color lineColor = Color.BLACK;
private Color fillColor = Color.WHITE;
private static final Color transparent = new Color(0, 0, 0, 0);
/** Create a new label, initialise it with the int value to be shown and the font size */
public Label(int value, int fontSize) {
this(Integer.toString(value), fontSize);
}
/** Create a new label, initialise it with the needed text and the font size */
public Label(String value, int fontSize) {
this.value = value;
this.fontSize = fontSize;
updateImage();
}
/**
* Sets the value as text
*
* @param value the text to be show
*/
public void setValue(String value) {
this.value = value;
updateImage();
}
/**
* Sets the value as integer
*
* @param value the value to be show
*/
public void setValue(int value) {
this.value = Integer.toString(value);
updateImage();
}
/**
* Sets the line color of the text
*
* @param lineColor the line color of the text
*/
public void setLineColor(Color lineColor) {
this.lineColor = lineColor;
updateImage();
}
/**
* Sets the fill color of the text
*
* @param fillColor the fill color of the text
*/
public void setFillColor(Color fillColor) {
this.fillColor = fillColor;
updateImage();
}
/** Update the image on screen to show the current value. */
private void updateImage() {
setImage(new GreenfootImage(value, fontSize, fillColor, transparent, lineColor));
}
}