source: winedb/src/gamegui/Label.java@ 9b6a069

Last change on this file since 9b6a069 was 9b6a069, checked in by dportnoy <devnull@…>, 13 years ago

Initial commit

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