package gamegui; import java.awt.*; public class Label extends Member { private String text; public Color color; private Font font; private Align alignment; public Label(String newName, int newX, int newY, int newWidth, int newHeight, String newText, Font newFont) { super(newName, newX, newY, newWidth, newHeight); text = newText; color = Color.green; font = newFont; alignment = Align.Center; } public Label(String newName, int newX, int newY, int newWidth, int newHeight, String newText, Font newFont, Color color) { super(newName, newX, newY, newWidth, newHeight); text = newText; this.color = color; font = newFont; alignment = Align.Center; } public Label(String newName, int newX, int newY, int newWidth, int newHeight, String newText, Font newFont, Align alignment) { super(newName, newX, newY, newWidth, newHeight); text = newText; color = Color.green; font = newFont; this.alignment = alignment; } public void setText(String s) { text = s; } public void draw(Graphics g) { FontMetrics metrics = g.getFontMetrics(font); g.setColor(color); g.setFont(font); switch(alignment) { case Center: g.drawString(text, getX() + (getWidth() - metrics.stringWidth(text))/2, getY() + (getHeight() + metrics.getHeight())/2 - 2); break; case Right: g.drawString(text, getX()+getWidth()-metrics.stringWidth(text), getY() + (getHeight() + metrics.getHeight())/2 - 2); break; case Left: g.drawString(text, getX(), getY() + (getHeight() + metrics.getHeight())/2 - 2); break; } } }