-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLabel.java
More file actions
73 lines (67 loc) · 2.1 KB
/
Copy pathLabel.java
File metadata and controls
73 lines (67 loc) · 2.1 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
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
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Class Label represents a text label on the world.
*
* Modifed from my own grade 11 final project.
*
* @author Yixin Cai
* @version 2022-01-28
*/
public class Label extends Actor
{
// Instance variables
private String labelText;
private int labelSize;
private Color labelColor = new Color(10, 186,181);
/**
* Constructors for objects of class Label.
* @param labelText The text that show on the world
*/
// Constructor taking label text
public Label(String labelText) {
this(labelText, 30);
}
// Constructor taking label text and label size
/**
* Constructors for objects of class Label.
* @param labelText The text that show on the world
* @param labelSize The size of the label
*/
public Label(String labelText, int labelSize) {
this.labelText = labelText;
// Set the size of the letters.
this.labelSize = labelSize;
// Putt image.
putLabelImage();
}
// Constructor taking label text, label size and label color
/**
* Constructors for objects of class Label.
* @param labelText The text that show on the world
* @param labelSize The size of the label
* @param labelColor the color of the label
*/
public Label(String labelText, int labelSize, Color labelColor) {
this.labelText = labelText;
// Set the size of the letters.
this.labelSize = labelSize;
// Set the clours of the letters.
this.labelColor = labelColor;
// Putt image.
putLabelImage();
}
/**
* Method to set the text to image
*/
private void putLabelImage() {
setImage( new GreenfootImage( this.labelText, this.labelSize, this.labelColor, new Color(0,0,0,0), new Color(0,0,0,0)));
}
/**
* Method to update the label text
* @param labelText The text that show on the world
*/
public void updateLabel( String labelText) {
this.labelText = labelText;
putLabelImage();
}
}