[8edd04e] | 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 Align alignment;
|
---|
| 10 |
|
---|
| 11 | public Label(String newName, int newX, int newY, int newWidth, int newHeight, String newText, Font newFont) {
|
---|
| 12 | super(newName, newX, newY, newWidth, newHeight);
|
---|
| 13 | this.text = newText;
|
---|
| 14 | this.font = newFont;
|
---|
| 15 | this.alignment = Align.Center;
|
---|
| 16 | }
|
---|
| 17 |
|
---|
| 18 | public Label(String newName, int newX, int newY, int newWidth, int newHeight, String newText, Font newFont, Align alignment) {
|
---|
| 19 | super(newName, newX, newY, newWidth, newHeight);
|
---|
| 20 | this.text = newText;
|
---|
| 21 | this.font = newFont;
|
---|
| 22 | this.alignment = alignment;
|
---|
| 23 | }
|
---|
| 24 |
|
---|
| 25 | public void setText(String s) {
|
---|
| 26 | this.text = s;
|
---|
| 27 | }
|
---|
| 28 |
|
---|
| 29 | public void draw(Graphics g) {
|
---|
| 30 | FontMetrics metrics = g.getFontMetrics(this.font);
|
---|
| 31 | g.setColor(Color.green);
|
---|
| 32 | g.setFont(this.font);
|
---|
| 33 | switch (this.alignment) {
|
---|
| 34 | case Center:
|
---|
| 35 | g.drawString(this.text, getX() + (getWidth() - metrics.stringWidth(this.text)) / 2, getY() + (getHeight() + metrics.getHeight()) / 2 - 2);
|
---|
| 36 | break;
|
---|
| 37 | case Right:
|
---|
| 38 | g.drawString(this.text, getX() + getWidth() - metrics.stringWidth(this.text), getY() + (getHeight() + metrics.getHeight()) / 2 - 2);
|
---|
| 39 | break;
|
---|
| 40 | case Left:
|
---|
| 41 | g.drawString(this.text, getX(), getY() + (getHeight() + metrics.getHeight()) / 2 - 2);
|
---|
| 42 | break;
|
---|
| 43 | }
|
---|
| 44 | }
|
---|
| 45 | }
|
---|