acm.graphics
Class GLine

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

public class GLine
extends GObject
implements GScalable

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


Field Summary
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.
 GRectangle getBounds()
Returns the bounding box for this object.
 GPoint getEndPoint()
Returns the end point of the line as a GPoint object.
 GPoint getStartPoint()
Returns the coordinates of the initial point in the line.
 void scale(double sf)
Scales the object on the screen by the scale factor sf, which applies in both dimensions.
 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 end point of the line to the point (xy).
 void setStartPoint(double x, double y)
Sets the initial point in the line to (xy), leaving the end point unchanged.
 
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.
ColorgetColor()
Returns the color used to display this object.
booleanisVisible()
Checks to see whether this object is visible.
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 this object.
voidsetVisible(boolean visible)
Sets whether this object is visible.
 

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.

See Also:
Constant Field Values
Constructor Detail

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

Constructs a line segment from its endpoints. The point (x0y0) defines the start of the line and the point (x1y1) defines the end.

 
Usage: GLine gline = new GLine(x0, y0, x1, y1); 
Parameters: 
x0  The x-coordinate of the start of the line
y0  The y-coordinate of the start of the line
x1  The x-coordinate of the end of the line
y1  The y-coordinate of the end of the line
 

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 (gline.contains(x, y)) . . . 
Parameters: 
 The x-coordinate of the point being tested
 The y-coordinate of the point being tested
Returns: true if the point (xy) is inside
 


public GRectangle getBounds()

Returns the bounding box for this object.

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

Specified by:
getBounds in class GObject

public GPoint getEndPoint()

Returns the end point of the line as a GPoint object.

 
Usage: GPoint pt = gline.getEndPoint(); 
Returns: The coordinates of the end point of the line
 


public GPoint getStartPoint()

Returns the coordinates of the initial point in the line. This method is identical to getLocation and exists only to provide symmetry with setStartPoint.

 
Usage: GPoint pt = gline.getStartPoint(); 
Returns: The coordinates of the origin of the line
 


public final void scale(double sf)

Scales the object on the screen by the scale factor sf, which applies in both dimensions.

 
Usage: gobj.scale(sf); 
Parameter: 
sf  The factor used to scale all coordinates in both dimensions
 

Specified by:
scale in interface GScalable

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 end point of the line, leaving the start of the line fixed.

 
Usage: gline.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
 

Specified by:
scale in interface GScalable

public void setEndPoint(double x, double y)

Sets the end point of the line to the point (xy). The origin of the line remains unchanged.

 
Usage: gline.setEndPoint(x, y); 
Parameters: 
 The new x-coordinate of the end point
 The new y-coordinate of the end point
 


public void setStartPoint(double x, double y)

Sets the initial point in the line to (xy), leaving the end point unchanged. This method is therefore different from setLocation, which moves both components of the line segment.

 
Usage: gline.setStartPoint(x, y); 
Parameters: 
 The new x-coordinate of the origin
 The new y-coordinate of the origin