source: java-rpg-client/gamegui/Label.java@ 55522be

Last change on this file since 55522be was 55522be, checked in by dportnoy <dmp1488@…>, 17 years ago

[svn r8]

  • Property mode set to 100644
File size: 1.2 KB
RevLine 
[55522be]1package gamegui;
2
3import java.awt.*;
4
5public class Label extends Member
6{
7 private String text;
8 private Font font;
9 private boolean centered;
10 private boolean fixed;
11
12 public Label(String newName, int newX, int newY, int newWidth, int newHeight, String newText, Font newFont, boolean centered) {
13 super(newName, newX, newY, newWidth, newHeight);
14
15 text = newText;
16 font = newFont;
17 this.centered = centered;
18 fixed = false;
19 }
20
21 public Label(String newName, int newX, int newY, int newWidth, int newHeight, String newText, Font newFont, boolean centered, boolean fixed) {
22 super(newName, newX, newY, newWidth, newHeight);
23
24 text = newText;
25 font = newFont;
26 this.centered = centered;
27 this.fixed = fixed;
28 }
29
30 public void setText(String s) {
31 text = s;
32 }
33
34 public void draw(Graphics g) {
35 FontMetrics metrics = g.getFontMetrics(font);
36
37 g.setColor(Color.green);
38 g.setFont(font);
39
40 if(centered)
41 g.drawString(text, getX() + (getWidth() - metrics.stringWidth(text))/2, getY() + (getHeight() + metrics.getHeight())/2 - 2);
42 else if(fixed)
43 g.drawString(text, getX(), getY());
44 else
45 g.drawString(text, getX(), getY() + (getHeight() + metrics.getHeight())/2 - 2);
46 }
47}
Note: See TracBrowser for help on using the repository browser.