| 
 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectgpdraw.DrawingTool
public class DrawingTool
DrawingTool is a graphics environment that provides methods for a programmer
  to draw pictures by moving an object (called a DrawingTool)
  around on the screen
  The center of the graphics window is at location 0,0. Positive X is to
  the right; positive Y is up. Headings (angles) are measured in degrees
  counterclockwise from the positive X axis.
  
| Field Summary | |
|---|---|
| protected  java.awt.Color | color | 
| protected  double | direction | 
| protected  boolean | isDown | 
| protected  SketchPadPanel | pad | 
| protected  int | width | 
| protected  double | xPos | 
| protected  double | yPos | 
| Constructor Summary | |
|---|---|
| DrawingTool()Constructor. | |
| DrawingTool(long delay)Constructor. | |
| DrawingTool(SketchPad win)Constructor. | |
| Method Summary | |
|---|---|
|  void | backward(double distance)This DrawingToolobject is moved backward from current direction bydistancepixels from the old (previous) location. | 
|  void | down()This object is set to drawing mode. | 
|  void | drawCircle(double radius)If the object is in drawing mode, Draws a circle of radius radiusaround the current location using the current width and color. | 
| protected  void | drawLine(double x,
         double y) | 
|  void | drawOval(double boundingBoxWidth,
         double boundingBoxHeight)Draws the outline of an oval. | 
|  void | drawRect(double recWidth,
         double recHeight)Draws the outline of the specified rectangle. | 
|  void | drawString(java.lang.String text)Draw the string textat the current location using the
  current color. | 
|  void | fillCircle(double radius)If the object is in drawing mode, Draws and fills a circle of radius radiusaround the current location using the current pen
  width and color. | 
|  void | fillOval(double boundingBoxWidth,
         double boundingBoxHeight)Fills the specified oval. | 
|  void | fillRect(double recWidth,
         double recHeight)Fills the specified rectangle. | 
|  void | forward(double distance)This DrawingToolobject is moved forward from current direction bydistancepixels from the old (previous) location. | 
|  java.awt.Color | getColor()Gets the color of the DrawingTool | 
|  double | getDirection()Gets the direction of this DrawingTool. | 
|  SketchPadPanel | getPadPanel()Returns the SketchPadPanelobject for thisDrawingTool. | 
|  java.awt.geom.Point2D.Double | getPosition()Gets the xandycoordinates of the current
  postion of thisDrawingTool. | 
|  int | getWidth()Get the drawing width of the DrawingTool | 
|  double | getXPos()Gets the xcoordinate of the current postion of thisDrawingTool. | 
|  double | getYPos()Gets the ycoordinate of the current postion of thisDrawingTool. | 
|  void | home()The location of the DrawingToolobject is set to the center of the
  SketchPad window with the drawing direction of the object set to up. | 
| protected  void | initialize(SketchPadPanel spadPanel)Initializes the state of this DrawingTool. | 
|  boolean | isDown()Get the drawing width of the DrawingTool | 
|  void | move(double distance)This DrawingToolobject is moved in the current direction bydistancepixels from the old (previous) location. | 
|  void | move(double x,
     double y)This DrawingToolobject is moved from the current position to the
  position specified by the coordinates x and y. | 
|  void | setColor(java.awt.Color c)The color of the DrawingToolobject is set toc. | 
|  void | setDirection(double deg)Sets the direction to d degrees. | 
|  void | setWidth(int width)Sets the width of the DrawingToolobject is towidthpixels. | 
|  java.lang.String | toString()Returns a string representation of this object. | 
|  void | turn(double degrees)Changes the current direction counterclockwise by degreesdegrees from the current direction | 
| protected  void | turn(double x,
     double y) | 
|  void | turnLeft()Changes the current direction counterclockwise by 90 degrees from the current direction | 
|  void | turnLeft(double degrees)Changes the current direction counterclockwise by degreesdegrees from the current direction | 
|  void | turnRight()Changes the current direction clockwise by 90 degrees from the current direction | 
|  void | turnRight(double degrees)Changes the current direction clockwise by degreesdegrees from the current direction | 
|  void | up()This object is set to moving mode. | 
| Methods inherited from class java.lang.Object | 
|---|
| clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait | 
| Field Detail | 
|---|
protected double xPos
protected double yPos
protected double direction
protected int width
protected boolean isDown
protected java.awt.Color color
protected SketchPadPanel pad
| Constructor Detail | 
|---|
public DrawingTool()
DrawingTool is created and placed in the
                center (0, 0) of a SketchPad window that is 250 pixels wide
                and 250 pixels high. This object is set to drawing mode.
                The direction for this object is up (90º). The DrawingTool
                color is set to black. The DrawingTool width is 1.
public DrawingTool(long delay)
DrawingTool is created and placed in the center (0, 0)
                of a SketchPad window that is 250 pixels wide and 250 pixels
                high. This object is set to drawing mode. The direction for
                this object is up (90º). The DrawingTool color is set to black.
                The DrawingTool width is 1.The drawing speed (in milliseconds)
                is determined by the delay parameter
delay - delay (ms) between DrawingTool drawing movementspublic DrawingTool(SketchPad win)
DrawingTool is created and placed in the center (0, 0)
                of the SketchPad window win. This object is set
                to drawing mode. The direction for this object is up (90º).
                The DrawingTool color is set to black. The DrawingTool
                width is 1.
| Method Detail | 
|---|
protected void initialize(SketchPadPanel spadPanel)
spadPanel - SketchPadPanel that contains this DrawingToolpublic java.awt.Color getColor()
DrawingTool
DrawingToolpublic int getWidth()
DrawingTool
DrawingToolpublic boolean isDown()
DrawingTool
true if this DrawingTool is in drawing
          mode (down); false otherwisepublic double getXPos()
x coordinate of the current postion of this
  DrawingTool.
x coordinate of this DrawingToolpublic double getYPos()
y coordinate of the current postion of this
  DrawingTool.
y coordinate of this DrawingToolpublic java.awt.geom.Point2D.Double getPosition()
x and y coordinates of the current
  postion of this DrawingTool.
x and y coordinates of the current
          postion of this DrawingTool as a
          Point2D.Double.public double getDirection()
DrawingTool.
DrawingTool in degreespublic SketchPadPanel getPadPanel()
SketchPadPanel object for this DrawingTool.
SketchPadPanel propertypublic void down()
public void home()
DrawingTool object is set to the center of the
  SketchPad window with the drawing direction of the object set to up.
public void move(double distance)
DrawingTool object is moved in the current direction by
  distance pixels from the old (previous) location.
  If this object is in drawing mode, a line segment is drawn across
  the distance path just traversed.
distance - pixels to move from the current location
public void move(double x,
                 double y)
DrawingTool object is moved from the current position to the
  position specified by the coordinates x and y. If this object is in
  drawing mode, a line segment is drawn from the old (previous) position
  to the absolute position specified by x and y. The direction is changed
  to the heading given by the move from the previous postion to the current
  position.
x - x coordinate of destinationy - y coordinate of destinationpublic void forward(double distance)
DrawingTool object is moved forward from current direction by
  distance pixels from the old (previous) location. If this
  object is in drawing mode, a line segment is drawn across the distance
  path just traversed. The direction is unchanged. A delay occurs following
  this method’s execution.
distance - pixels to move forwards from the current locationpublic void backward(double distance)
DrawingTool object is moved backward from current direction by
  distance pixels from the old (previous) location. If this
  object is in drawing mode, a line segment is drawn across the distance
  path just traversed. The direction is unchanged. A delay occurs following
  this method’s execution.
distance - pixels to move backwards from the current locationpublic void setColor(java.awt.Color c)
DrawingTool object is set to c.
c - a valid Color objectpublic void setWidth(int width)
DrawingTool object is to width pixels.
width - width in pixels of the DrawingTool object
java.lang.RuntimeException - if width is < 1public void setDirection(double deg)
deg
  degrees counterclockwise from the positive x-axis
deg - degrees counterclockwise from the positive x-axispublic java.lang.String toString()
"DrawingTool["+
       "Position:"  + xPos + "," + yPos + " " +
       "Color:"     + color + " "  +
       "Width:"     + width + " " +
       "Is down:"   + isDown + " "  +
       "Direction:" + direction +
       ']'.
toString in class java.lang.Objectpublic void turn(double degrees)
degrees
  degrees from the current direction
degrees - degrees counterclockwise from the current directionpublic void turnLeft(double degrees)
degrees
  degrees from the current direction
degrees - degrees counterclockwise from the current directionpublic void turnLeft()
degrees - degrees counterclockwise from the current directionpublic void turnRight(double degrees)
degrees
  degrees from the current direction
degrees - degrees clockwise from the current directionpublic void turnRight()
degrees - degrees clockwise from the current directionpublic void up()
public void drawString(java.lang.String text)
text at the current location using the
  current color.
text - string to be drawnpublic void drawCircle(double radius)
radius
  around the current location using the current width and color.
radius - radius of circle to be drawnpublic void fillCircle(double radius)
radius around the current location using the current pen
  width and color.
radius - radius of the filled circle to be drawn
public void drawRect(double recWidth,
                     double recHeight)
x - recWidth/2 and x + recWidth/2.
  The top and bottom edges are at y - recHeight/2 and 
  y + recHeight/2. The rectangle is drawn using the
  DrawingTool's current color.
recWidth - width of the rectangle to be drawnrecHeight - height of the rectangle to be drawn
public void fillRect(double recWidth,
                     double recHeight)
x - recWidth/2 and x + recWidth/2.
  The top and bottom edges are at y - recHeight/2 and 
  y + recHeight/2. The rectangle is filled using the
  DrawingTool's current color.
recWidth - width of the rectangle to be filledrecHeight - height of the rectangle to be filled
public void drawOval(double boundingBoxWidth,
                     double boundingBoxHeight)
width, and height arguments.
  The left and right edges of the bounding rectangle are at
  x - recWidth/2 and x + recWidth/2.
  The top and bottom edges are at y - recHeight/2 and 
  y + recHeight/2. The oval is drawn using the
  DrawingTool's current color.
boundingBoxWidth - width of the oval to be drawnboundingBoxHeight - height of the oval to be drawn
public void fillOval(double boundingBoxWidth,
                     double boundingBoxHeight)
width, and height arguments.
  The left and right edges of the bounding rectangle are at
  x - recWidth/2 and x + recWidth/2.
  The top and bottom edges are at y - recHeight/2 and 
  y + recHeight/2. The oval is drawn using the
  DrawingTool's current color.
boundingBoxWidth - width of the oval to be filledboundingBoxHeight - height of the oval to be filled
protected void drawLine(double x,
                        double y)
protected void turn(double x,
                    double y)
| 
 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||