source: lost-perception/gamegui/Label.java

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

Initial commit. This codebase for the Lost Perception game was created by decompiling code from a jar file.

  • 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{
10 private String text;
11 public Color color;
12 private Font font;
13 private Align alignment;
14
15 public Label(final String newName, final int newX, final int newY, final int newWidth, final int newHeight, final String newText, final Font newFont) {
16 super(newName, newX, newY, newWidth, newHeight);
17 this.text = newText;
18 this.color = Color.green;
19 this.font = newFont;
20 this.alignment = Align.Center;
21 }
22
23 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) {
24 super(newName, newX, newY, newWidth, newHeight);
25 this.text = newText;
26 this.color = color;
27 this.font = newFont;
28 this.alignment = Align.Center;
29 }
30
31 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) {
32 super(newName, newX, newY, newWidth, newHeight);
33 this.text = newText;
34 this.color = Color.green;
35 this.font = newFont;
36 this.alignment = alignment;
37 }
38
39 public void setText(final String s) {
40 this.text = s;
41 }
42
43 @Override
44 public void draw(final Graphics g) {
45 final FontMetrics metrics = g.getFontMetrics(this.font);
46 g.setColor(this.color);
47 g.setFont(this.font);
48 switch (this.alignment) {
49 case Center: {
50 g.drawString(this.text, this.getX() + (this.getWidth() - metrics.stringWidth(this.text)) / 2, this.getY() + (this.getHeight() + metrics.getHeight()) / 2 - 2);
51 break;
52 }
53 case Right: {
54 g.drawString(this.text, this.getX() + this.getWidth() - metrics.stringWidth(this.text), this.getY() + (this.getHeight() + metrics.getHeight()) / 2 - 2);
55 break;
56 }
57 case Left: {
58 g.drawString(this.text, this.getX(), this.getY() + (this.getHeight() + metrics.getHeight()) / 2 - 2);
59 break;
60 }
61 }
62 }
63}
Note: See TracBrowser for help on using the repository browser.