acm.graphics
Class GLabel

java.lang.Object
  extended by acm.graphics.GObject
      extended by acm.graphics.GLabel

public class GLabel
extends GObject

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


Field Summary
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.
 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 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.
 
Inherited Method Summary
voidaddMouseListener(MouseListener listener)
Adds a mouse listener to this graphical object.
voidaddMouseMotionListener(MouseMotionListener listener)
Adds a mouse motion listener to this graphical object.
booleancontains(GPoint pt)
Checks to see whether a point is inside the object.
booleancontains(double x, double y)
Checks to see whether a point is "inside" the string, which is defined to be inside the bounding rectangle.
ColorgetColor()
Returns the color used to display the text of the GLabel.
GPointgetLocation()
Returns the location of the GLabel as a GPoint object.
GDimensiongetSize()
Returns the size of the bounding box for this object.
doublegetX()
Returns the x-coordinate of the object.
doublegetY()
Returns the y-coordinate of the object.
booleanisVisible()
Checks to see whether the GLabel is visible.
voidmove(double dx, double dy)
Moves the object on the screen using the displacements dx and dy.
voidmovePolar(double r, double theta)
Moves the object using displacements given in polar coordinates.
voidremoveMouseListener(MouseListener listener)
Removes a mouse listener from this graphical object.
voidremoveMouseMotionListener(MouseMotionListener listener)
Removes a mouse motion listener from this graphical object.
voidsendBackward()
Moves this object one step toward the back in the z dimension.
voidsendForward()
Moves this object one step toward the front in the z dimension.
voidsendToBack()
Moves this object to the back of the display in the z dimension.
voidsendToFront()
Moves this object to the front of the display in the z dimension.
voidsetColor(Color color)
Sets the color used to display the text of the GLabel.
voidsetLocation(GPoint pt)
Sets the location of this object to the specified point.
voidsetLocation(double x, double y)
Sets the location of the GLabel to the point (x, y). For a GLabel, the location is the point on the text baseline at which the text starts.
voidsetVisible(boolean visible)
Sets the visibility status of the GLabel.
 

Field Detail

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

public GLabel(String str)

Creates a new GLabel object initialized to contain the specified string.

 
Usage: GLabel glabel = new GLabel(str); 
Parameter: 
str  The initial contents of the GLabel
 


public GLabel(String str, double x, double y)

Creates a new GLabel object with its baseline origin at the specified position.

 
Usage: GLabel glabel = new GLabel(str, x, y); 
Parameters: 
str  The initial contents of the GLabel
 The x-coordinate of the label origin
 The y-coordinate of the baseline for the label
 

Method Detail

public double getAscent()

Returns the distance this string extends above the baseline.

 
Usage: double ascent = glabel.getAscent(); 
Returns: The ascent of this string in pixels
 


public GRectangle getBounds()

Returns a GRectangle that specifies the bounding box for the string.

 
Usage: GRectangle bounds = glabel.getBounds(); 
Returns: The bounding box for this object
 

Specified by:
getBounds in class GObject

public double getDescent()

Returns the distance this string descends below the baseline.

 
Usage: double descent = glabel.getDescent(); 
Returns: The descent of this string in pixels
 


public Font getFont()

Returns the font in which the GLabel is displayed.

 
Usage: Font font = glabel.getFont(); 
Returns: The font in use by this object
 


public double getHeight()

Returns the height of this string, as it appears on the display.

 
Usage: double height = glabel.getHeight(); 
Returns: The height of this string
 


public String getLabel()

Returns the string displayed by this object.

 
Usage: String str = glabel.getLabel(); 
Returns: The string displayed by this object
 


public double getWidth()

Returns the width of this string, as it appears on the display.

 
Usage: double width = glabel.getWidth(); 
Returns: The width of this object
 


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.

 
Usage: glabel.setFont(font); 
Parameter: 
font  A Font object indicating the new font
 


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.


 
Usage: glabel.setFont(str); 
Parameter: 
str  A String specifying the new font
 


public void setLabel(String str)

Changes the string stored within the GLabel object, so that a new text string appears on the display.

 
Usage: glabel.setLabel(str); 
Parameter: 
str  The new string to display