acm.graphics
Class GLabel

java.lang.Object
  extended by acm.graphics.GObject
      extended by acm.graphics.GLabel
All Implemented Interfaces:
Serializable, Cloneable

public class GLabel
extends GObject

The GLabel class is a graphical object whose appearance consists of a text string.

See Also:
Serialized Form

Field Summary
static Font DEFAULT_FONT
          The default font used to display strings.
 
Constructor Summary
GLabel(String str)
          Creates a new GLabel object initialized to contain the specified string.
GLabel(String str, double x, double y)
          Creates a new GLabel object with its baseline origin at the specified position.
 
Method Summary
 double getAscent()
          Returns the distance this string extends above the baseline.
 GRectangle getBounds()
          Returns a GRectangle that specifies the bounding box for the string.
 double getDescent()
          Returns the distance this string descends below the baseline.
 Font getFont()
          Returns the font in which the GLabel is displayed.
 FontMetrics getFontMetrics()
          Returns a FontMetrics object describing the dimensions of this string.
 double getHeight()
          Returns the height of this string, as it appears on the display.
 String getLabel()
          Returns the string displayed by this object.
 double getWidth()
          Returns the width of this string, as it appears on the display.
 void paint(Graphics g)
          Implements the paint operation for this graphical object.
 String paramString()
          Returns a string indicating the parameters of this object.
 void setFont(Font font)
          Changes the font used to display the GLabel.
 void setFont(String str)
          Changes the font used to display the GLabel as specified by the string str, which is interpreted in the style of Font.decode.
 void setLabel(String str)
          Changes the string stored within the GLabel object, so that a new text string appears on the display.
 
Methods inherited from class acm.graphics.GObject
addActionListener, addMouseListener, addMouseMotionListener, areMouseListenersEnabled, colorName, contains, contains, fireActionEvent, fireActionEvent, fireMouseListeners, getColor, getComponent, getLocation, getObjectColor, getParent, getSize, getX, getY, isVisible, move, movePolar, paintObject, pause, removeActionListener, removeMouseListener, removeMouseMotionListener, repaint, sendBackward, sendForward, sendToBack, sendToFront, setColor, setLocation, setLocation, setParent, setVisible, start, start, toString, updateEnabledList
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_FONT

public static final Font DEFAULT_FONT
The default font used to display strings. You can change the font by invoking the setFont method.

Constructor Detail

GLabel

public GLabel(String str)
Creates a new GLabel object initialized to contain the specified string.

Parameters:
str - The initial contents of the GLabel

GLabel

public GLabel(String str,
              double x,
              double y)
Creates a new GLabel object with its baseline origin at the specified position.

Parameters:
str - The initial contents of the GLabel
x - The x-coordinate of the label origin
y - The y-coordinate of the baseline for the label
Method Detail

getAscent

public double getAscent()
Returns the distance this string extends above the baseline.

Returns:
The ascent of this string in pixels

getBounds

public GRectangle getBounds()
Returns a GRectangle that specifies the bounding box for the string.

Specified by:
getBounds in class GObject
Returns:
The bounding box for this object

getDescent

public double getDescent()
Returns the distance this string descends below the baseline.

Returns:
The descent of this string in pixels

getFont

public Font getFont()
Returns the font in which the GLabel is displayed.

Returns:
The font in use by this object

getFontMetrics

public FontMetrics getFontMetrics()
Returns a FontMetrics object describing the dimensions of this string.

Returns:
A FontMetrics object describing the dimensions of this string

getHeight

public double getHeight()
Returns the height of this string, as it appears on the display.

Overrides:
getHeight in class GObject
Returns:
The height of this string

getLabel

public String getLabel()
Returns the string displayed by this object.

Returns:
The string displayed by this object

getWidth

public double getWidth()
Returns the width of this string, as it appears on the display.

Overrides:
getWidth in class GObject
Returns:
The width of this object

paint

public void paint(Graphics g)
Implements the paint operation for this graphical object. This method is not called directly by clients.

Specified by:
paint in class GObject
Parameters:
g - The graphics context into which the painting is done

paramString

public String paramString()
Returns a string indicating the parameters of this object.

Overrides:
paramString in class GObject

setFont

public void setFont(Font font)
Changes the font used to display the GLabel. This call will usually change the size of the displayed object and will therefore affect the result of calls to getSize and getBounds.

Parameters:
font - A Font object indicating the new font

setFont

public void setFont(String str)
Changes the font used to display the GLabel as specified by the string str, which is interpreted in the style of Font.decode. The usual format of the font string is


      family-style-size

 

where both style and size are optional. If any of these parts are specified as an asterisk, the existing value is retained.

Parameters:
str - A String specifying the new font

setLabel

public void setLabel(String str)
Changes the string stored within the GLabel object, so that a new text string appears on the display.

Parameters:
str - The new string to display