-
Notifications
You must be signed in to change notification settings - Fork 1
/
Label.java
100 lines (84 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import java.awt.*;
import java.awt.geom.AffineTransform;
class Label
{
private String text;
private int x;
private int y;
private int size = 24;
private Color color = Color.WHITE;
private boolean isVisible = true;
private String font = "Courier";
private double rotation = 0.0;
Label(String text, int x, int y)
{
this.text = text;
this.x = x;
this.y = y;
}
public void render(Graphics g)
{
Font font = new Font(this.font, Font.PLAIN, size);
g.setFont(font);
g.setColor(this.color);
if(this.isVisible)
{
if(rotation != 0)
{
AffineTransform affineTransform = new AffineTransform();
affineTransform.rotate(Math.toRadians(this.rotation), 0, 0);
Font rotatedFont = font.deriveFont(affineTransform);
g.setFont(rotatedFont);
g.drawString(text, x, y);
}
else
{
g.drawString(text, x, y);
}
}
}
public void setText(String text)
{
this.text = text;
}
public void setColor(Color color)
{
this.color = color;
}
public void setX(int x)
{
this.x = x;
}
public void setY(int y)
{
this.y = y;
}
public void setSize(int size)
{
this.size = size;
}
public void show()
{
this.isVisible = true;
}
public void hide()
{
this.isVisible = false;
}
public void setRotation(int rotation)
{
this.rotation = -rotation;
}
public void setRotation(double rotation)
{
this.rotation = -(int)rotation;
}
public void setFont(String font)
{
this.font = font;
}
public String getFont()
{
return this.font;
}
}