1 | package gamegui;
|
---|
2 |
|
---|
3 | import java.awt.*;
|
---|
4 |
|
---|
5 | public class Label extends Member
|
---|
6 | {
|
---|
7 | private String text;
|
---|
8 | private Font font;
|
---|
9 | private boolean centered;
|
---|
10 | private boolean fixed;
|
---|
11 |
|
---|
12 | public Label(String newName, int newX, int newY, int newWidth, int newHeight, String newText, Font newFont, boolean centered) {
|
---|
13 | super(newName, newX, newY, newWidth, newHeight);
|
---|
14 |
|
---|
15 | text = newText;
|
---|
16 | font = newFont;
|
---|
17 | this.centered = centered;
|
---|
18 | fixed = false;
|
---|
19 | }
|
---|
20 |
|
---|
21 | public Label(String newName, int newX, int newY, int newWidth, int newHeight, String newText, Font newFont, boolean centered, boolean fixed) {
|
---|
22 | super(newName, newX, newY, newWidth, newHeight);
|
---|
23 |
|
---|
24 | text = newText;
|
---|
25 | font = newFont;
|
---|
26 | this.centered = centered;
|
---|
27 | this.fixed = fixed;
|
---|
28 | }
|
---|
29 |
|
---|
30 | public void setText(String s) {
|
---|
31 | text = s;
|
---|
32 | }
|
---|
33 |
|
---|
34 | public void draw(Graphics g) {
|
---|
35 | FontMetrics metrics = g.getFontMetrics(font);
|
---|
36 |
|
---|
37 | g.setColor(Color.green);
|
---|
38 | g.setFont(font);
|
---|
39 |
|
---|
40 | if(centered)
|
---|
41 | g.drawString(text, getX() + (getWidth() - metrics.stringWidth(text))/2, getY() + (getHeight() + metrics.getHeight())/2 - 2);
|
---|
42 | else if(fixed)
|
---|
43 | g.drawString(text, getX(), getY());
|
---|
44 | else
|
---|
45 | g.drawString(text, getX(), getY() + (getHeight() + metrics.getHeight())/2 - 2);
|
---|
46 | }
|
---|
47 | }
|
---|