import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.awt.*; /** * Something that contains some text and can be shown in the world. * * @author Martin Schend, Jannis Andrija Schnitzer * @version 2011-01-21 */ public class Label extends Actor { protected Color color; protected Font font; protected String text; public static final Color DEFAULT_COLOR = Color.WHITE; public static final Font DEFAULT_FONT = new Font("Verdana", Font.BOLD, 42); public Label(String the_text) { this(the_text, DEFAULT_COLOR, DEFAULT_FONT); } public Label(String the_text, Color the_color) { this(the_text, the_color, DEFAULT_FONT); } public Label(String the_text, Font the_font) { this(the_text, DEFAULT_COLOR, the_font); } public Label(String the_text, Color the_color, Font the_font) { text = the_text; color = the_color; font = the_font; setText(text); } public void setColor(Color newColor) { color = newColor; setText(text); } public Color getColor() { return color; } public void setFont(Font newFont) { font = newFont; setText(text); } public Font getFont() { return font; } public void setText(String text) { GreenfootImage img = new GreenfootImage(text.length()*40, 50); img.setColor(color); img.setFont(font); img.drawString(text, 2, 50); setImage(img); } }