acm.graphics
Class GLine

java.lang.Object
  |
  +--acm.graphics.GObject
        |
        +--acm.graphics.GLine

public class GLine extends GObject

The GLine class is a graphical object whose appearance consists of a line segment.

[examples forthcoming]


Field Summary
static double LINE_TOLERANCE
This constant defines how close (measured in pixel units) a point has to be to a line before that point is considered to be "contained" within the line.
 
Constructor Summary
GLine(double x0, double y0, double x1, double y1)
Constructs a line segment from its endpoints.
 
Method Summary
boolean contains(double x, double y)
Checks to see whether a point is inside the object.
Rectangle getBounds()
Returns the bounding box for this object.
Point getEndpoint()
Returns the endpoint of the line as a Point object.
Point getOrigin()
Returns the coordinates of the initial point in the line.
void paint(Graphics g)
Implements the paint operation for this graphical object.
void scale(double sx, double sy)
Scales the line on the screen by the scale factors sx and sy.
void setEndpoint(double x, double y)
Sets the endpoint of the line to the point (xy).
void setOrigin(double x, double y)
Sets the origin of the line to the point (xy), leaving the endpoint unchanged.
 

Inherited Method Summary
void addMouseListener(MouseListener listener)
Adds a mouse listener to this graphical object. [Inherited from GObject]
void addMouseMotionListener(MouseMotionListener listener)
Adds a mouse motion listener to this graphical object. [Inherited from GObject]
Color getColor()
Returns the color used to display this object. [Inherited from GObject]
boolean isFilled()
Returns whether this object is filled. [Inherited from GObject]
boolean isVisible()
Checks to see whether this object is visible. [Inherited from GObject]
void moveToBack()
Moves this object to the back of the display in stacking order. [Inherited from GObject]
void moveToFront()
Moves this object to the front of the display in stacking order. [Inherited from GObject]
void removeMouseListener(MouseListener listener)
Removes a mouse listener from this graphical object. [Inherited from GObject]
void removeMouseMotionListener(MouseMotionListener listener)
Removes a mouse motion listener from this graphical object. [Inherited from GObject]
void setColor(Color c)
Sets the color used to display this object. [Inherited from GObject]
void setFilled(boolean fill)
Sets whether this object is filled. [Inherited from GObject]
void setVisible(boolean visible)
Sets whether this object is visible. [Inherited from GObject]

Field Detail

public static final double LINE_TOLERANCE

This constant defines how close (measured in pixel units) a point has to be to a line before that point is considered to be "contained" within the line.
Constructor Detail

public GLine(double x0, double y0, double x1, double y1)

Constructs a line segment from its endpoints. The point (x0y0) defines the origin of the line and the point (x1y1) defines the endpoint.
 
Usage: GLine gpt = new GLine(x0, y0, x1, y1);
Parameters: 
x0  The x-coordinate of the origin of the line
y0  The y-coordinate of the origin of the line
x1  The x-coordinate of the endpoint
y1  The y-coordinate of the endpoint
 
Method Detail

public boolean contains(double x, double y)

Checks to see whether a point is inside the object. For the GLine class, containment is defined to mean that the point is within LINE_TOLERANCE pixels of the line.
 
Usage: if (gpt.contains(x, y)) . . .
Parameters: 
x  The x-coordinate of the point being tested
y  The y-coordinate of the point being tested
Returns: true if the point (xy) is inside
 

public Rectangle getBounds()

Returns the bounding box for this object.
 
Usage: Rectangle bounds = gpt.getBounds();
Returns: The bounding box for this object
 

public Point getEndpoint()

Returns the endpoint of the line as a Point object.
 
Usage: Point pt = gpt.getEndpoint();
Returns: The coordinates of the endpoint of the line
 

public Point getOrigin()

Returns the coordinates of the initial point in the line. This method is identical to getLocation and exists only to provide symmetry with setOrigin.
 
Usage: Point pt = gpt.getOrigin();
Returns: The coordinates of the origin of the line
 

public void paint(Graphics g)

Implements the paint operation for this graphical object. This method is not called directly by clients.

public void scale(double sx, double sy)

Scales the line on the screen by the scale factors sx and sy. This method changes only the endpoint of the line, leaving the start of the line fixed.
 
Usage: gpt.scale(sx, sy);
Parameters: 
sx  The factor used to scale all coordinates in the x direction
sy  The factor used to scale all coordinates in the y direction
 

public void setEndpoint(double x, double y)

Sets the endpoint of the line to the point (xy). The origin of the line remains unchanged.
 
Usage: gpt.setEndpoint(x, y);
Parameters: 
x  The new x-coordinate of the endpoint
y  The new y-coordinate of the endpoint
 

public void setOrigin(double x, double y)

Sets the origin of the line to the point (xy), leaving the endpoint unchanged. This method is therefore different from setLocation, which moves both components of the line segment.
 
Usage: gpt.setOrigin(x, y);
Parameters: 
x  The new x-coordinate of the origin
y  The new y-coordinate of the origin