DRAWINGTOOL CLASS SPECIFICATIONS

 

These classes are not part of Java but are available through the library named apcslib.  You must have the file apcslib.jar in the appropriate directory where Java can access it.  To have these classes available in your program, use this command:

import apcslib.*;

Other features of apcslib will be covered in later lessons.

 

 

DrawingTool

 

 

protected double

protected xPos

protected yPos

protected direction;

protected int width;

protected boolean isDown;

protected Color color;   

...

 

 

<<constructors>>

DrawingTool()

DrawingTool(SketchPad)

...

 

<<accessors>>

public Color getColor()

public double getDirection()

public Point2D.Double getPosition()

public int getWidth()

public String toString()

 

<<modifiers>>

public void backward(double)

public void down()

public void drawString(String)

public void drawCircle(double)

public void forward(double)

public void home()

public void move(double)

public void move(double, double)

public void setColor(Color)

public void setDirection(double)

public void setWidth(int)

public String toString()

public void turn (double)

public void turnLeft(double)

public void turnRight(double)

public void up()

...

 

Invariant

 

A DrawingTool object

·         Appears in a SketchPad Window (this window is 250 pixels wide and 250 pixels high initially, but can be constructed with different dimensions.)

·         The origin (0, 0) is at the center of the drawing window.

·         Is directed either up, down, left, or right.

·         Is either in drawing mode or in moving mode.

 

Constructor Methods

 

public DrawingTool()

postcondition

·         A new 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 blue.

·         The DrawingTool width is 1.

 

public DrawingTool(SketchPad win)

postcondition

·         A new 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 blue.

·         The DrawingTool width is 1.

 

Accessor Methods

public String toString();

postcondition

result = color

public Color getColor();

postcondition

result = color

public double getDirection();

postcondition

result = direction

public int getWidth();

postcondition

result = width

 

 

Modifier Methods

public backward (double distance);

postcondition

·         This 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 0.5 second delay occurs following this method’s execution.

public void down();

postcondition

·         This object is set to drawing mode.

public drawString(String text);

postcondition

·         The string text is drawn at the current location using the current color.

public drawCircle (double r);

postcondition

·         If the object is in drawing mode, a circle of radius r is drawn around the current location using the current width and color.

public forward(double distance);

postcondition

·         This 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.

·         A 0.5 second delay occurs following this method’s execution.

public home();

postcondition

·         The location of the DrawingTool object is set to the center of the SketchPad window.

·         The drawing direction of the object is ups.

public move(double d);

postcondition

·         This DrawingTool object is moved in the current direction by d pixels from the old (previous) location.

·         If this object is in drawing mode, a line segment is drawn across the d path just traversed.

public move(double x, double y);

postcondition

·         This 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.

public setColor(Color c);

precondition

·         c is a valid Color

postcondition

·         The color of the DrawingTool object is set to c.

public setDirection(double d);

postcondition

·         Sets the direction to d degrees. The orientation is d degrees counterclockwise from the positive x-axis

public setWidth(int w);

precondition

·         w is >= 1

postcondition

·         The width of the DrawingTool object is set to w pixels.

public turn(double d);

postcondition

·         Changes the current direction counterclockwise by d degrees from the current direction.

public turnLeft(double degrees);

postcondition

·         Changes the current direction counterclockwise by d degrees from the current direction.

public turnRight(double degrees);

postcondition

·         Changes the current direction clockwise by d degrees from the current direction.

public up();

postcondition

·         This object is set to moving mode.