source: last-defense/gamegui/Label.java

Last change on this file was fb4fc67, checked in by Dmitry Portnoy <dmitry.portnoy@…>, 6 years ago

Initial commit, code decompiled from a jar

  • Property mode set to 100644
File size: 2.3 KB
Line 
1package gamegui;
2
3import java.awt.FontMetrics;
4import java.awt.Graphics;
5import java.awt.Font;
6import java.awt.Color;
7
8public class Label extends Member {
9 private String text;
10 public Color color;
11 private Font font;
12 private Align alignment;
13
14 public Label(final String newName, final int newX, final int newY, final int newWidth, final int newHeight, final String newText, final Font newFont) {
15 super(newName, newX, newY, newWidth, newHeight);
16 this.text = newText;
17 this.color = Color.green;
18 this.font = newFont;
19 this.alignment = Align.Center;
20 }
21
22 public Label(final String newName, final int newX, final int newY, final int newWidth, final int newHeight, final String newText, final Font newFont, final Color color) {
23 super(newName, newX, newY, newWidth, newHeight);
24 this.text = newText;
25 this.color = color;
26 this.font = newFont;
27 this.alignment = Align.Center;
28 }
29
30 public Label(final String newName, final int newX, final int newY, final int newWidth, final int newHeight, final String newText, final Font newFont, final Align alignment) {
31 super(newName, newX, newY, newWidth, newHeight);
32 this.text = newText;
33 this.color = new Color(0, 160, 0);
34 this.font = newFont;
35 this.alignment = alignment;
36 }
37
38 public String getText() {
39 return this.text;
40 }
41
42 public void setText(final String s) {
43 this.text = s;
44 }
45
46 @Override
47 public void draw(final Graphics g) {
48 final FontMetrics metrics = g.getFontMetrics(this.font);
49 g.setColor(this.color);
50 g.setFont(this.font);
51 switch (this.alignment) {
52 case Center: {
53 g.drawString(this.text, this.getX() + (this.getWidth() - metrics.stringWidth(this.text)) / 2, this.getY() + (this.getHeight() + metrics.getHeight()) / 2 - 2);
54 break;
55 }
56 case Right: {
57 g.drawString(this.text, this.getX() + this.getWidth() - metrics.stringWidth(this.text), this.getY() + (this.getHeight() + metrics.getHeight()) / 2 - 2);
58 break;
59 }
60 case Left: {
61 g.drawString(this.text, this.getX(), this.getY() + (this.getHeight() + metrics.getHeight()) / 2 - 2);
62 break;
63 }
64 }
65 }
66}
Note: See TracBrowser for help on using the repository browser.