Last change
on this file since 7d9c033 was 7d9c033, checked in by Dmitry Portnoy <dmitry.portnoy@…>, 6 years ago |
Initial commit, code decompiled from a jar
|
-
Property mode
set to
100644
|
File size:
1.1 KB
|
Line | |
---|
1 | package gamegui;
|
---|
2 |
|
---|
3 | import java.awt.FontMetrics;
|
---|
4 | import java.awt.Color;
|
---|
5 | import java.awt.Graphics;
|
---|
6 | import java.awt.Font;
|
---|
7 |
|
---|
8 | public class Label extends Member {
|
---|
9 | private String text;
|
---|
10 | private Font font;
|
---|
11 | private boolean centered;
|
---|
12 |
|
---|
13 | public Label(final String newName, final int newX, final int newY, final int newWidth, final int newHeight, final String newText, final Font newFont, final boolean isCentered) {
|
---|
14 | super(newName, newX, newY, newWidth, newHeight);
|
---|
15 | this.text = new String(newText);
|
---|
16 | this.font = newFont;
|
---|
17 | this.centered = isCentered;
|
---|
18 | }
|
---|
19 |
|
---|
20 | public void draw(final Graphics g) {
|
---|
21 | final FontMetrics metrics = g.getFontMetrics(this.font);
|
---|
22 | g.setColor(Color.green);
|
---|
23 | g.setFont(this.font);
|
---|
24 | if (this.centered) {
|
---|
25 | g.drawString(this.text, this.getX() + (this.getWidth() - metrics.stringWidth(this.text)) / 2, this.getY() + (this.getHeight() + metrics.getHeight()) / 2 - 2);
|
---|
26 | } else {
|
---|
27 | g.drawString(this.text, this.getX(), this.getY() + (this.getHeight() + metrics.getHeight()) / 2 - 2);
|
---|
28 | }
|
---|
29 | }
|
---|
30 | } |
---|
Note:
See
TracBrowser
for help on using the repository browser.