Summary of Objectdraw API

WindowController

Methods to Define within Classes that extend WindowController

void begin ()

Initialize the program.

void onMouseClick(Location point)

Define actions to take when the mouse button is clicked.

void onMousePress(Location point)

Define actions to take when the mouse button is pressed.

void onMouseRelease(Location point)

Define actions to take when the mouse button is released.

void onMouseEnter(Location point)

Define actions to take when the mouse enters the window.

void onMouseExit(Location point)

Define actions to take when the mouse exits the window.

void onMouseDrag(Location point)

Define actions to take when the mouse is moved with the mouse button down.

void onMouseMove(Location point)

Define actions to take when the mouse is moved with the mouse button up.

Methods to Call within Classes that extend WindowController

Image getImage(String fileName)

Loads a gif or jpeg file

Measuring Time

double System.currentTimeMillis()

Returns the time in milliseconds.


ActiveObject

Methods to Define within Classes that extend ActiveObject

void run()

The active behavior of the object.

Methods to Call within Classes that extend ActiveObject

void start()

Call this method at the end of the constructor. It will result in your active object coming to life with its run method executing.

void pause(double interval)

Causes the active object to pause execution for interval milliseconds.

double getTime()

Returns the time in milliseconds.


Drawable Objects

Constructors for Classes of Drawable Objects

FramedRect(double x, 
           double y, 
           double width,
           double height,
           DrawingCanvas canvas);
FramedRect(Location cornerLocation,  double width,  double height,  DrawingCanvas canvas);
FramedRect(Location corner1Location,  Location corner2Location,  DrawingCanvas canvas); FilledRect(double x,  double y,  double width, double height, DrawingCanvas canvas );
FilledRect(Location cornerLocation,  double width,  double height,  DrawingCanvas canvas);
FilledRect(Location corner1Location,  Location corner2Location,  DrawingCanvas canvas);

The parameters to a rectangle or oval constructor describe the rectangle bounding the object to be drawn. You can either:

  • Specify the coordinates of the rectangle's upper left corner together with the width and height, or
  • Specify the coordinates of two opposite corners.

You can fill these shapes or just frame their perimeters.

FramedOval(double x, 
           double y, 
           double width,
           double height,
           DrawingCanvas canvas);
FramedOval(Location cornerLocation,  double width,  double height,  DrawingCanvas canvas);
FramedOval(double x,  double y,  double width, double height, DrawingCanvas canvas); FilledOval(double x,  double y,  double width, double height, DrawingCanvas canvas);
FilledOval(Location cornerLocation,  double width,  double height,  DrawingCanvas canvas);
FilledOval(Location corner1Location,  Location corner2Location,  DrawingCanvas canvas);

VisibleImage(Image image, 
              Location origin, 
              DrawingCanvas c)
VisibleImage(Image image, 
              double x, 
              double y, 
              DrawingCanvas c)
VisibleImage(Image image, 
              Location origin, 
              int width, 
              int height, 
              DrawingCanvas c)
VisibleImage(Image image, 
              double x, 
              double y, 
              int width, 
              int height, 
              DrawingCanvas c)

The parameters to a drawable image constructor require you to specify the upper left corner of the image, either using a Location object or a pair of values for x and y. You can also optionally resize the image by giving a width and height. If you do not specify a width and height, it will use the size that the Image itself has.

Text(String text, 
     double x, 
     double y,  
     DrawingCanvas canvas);
Text(String text,  Location baseLocation, DrawingCanvas canvas);

The coordinates specify the leftmost point of the text's baseline.

Line(double startX, 
     double startY,  
     double endX, 
     double endY,
     DrawingCanvas canvas);
Line(Location startLocation, Location endLocation,  DrawingCanvas canvas);

A line is described by giving its end points.

Methods for All Drawable Classes

boolean contains(Location someLocation )

If a line, determine if the line contains a point; if 2-D, determine if the object's bounding box contains a point.

Color getColor()
void setColor (Color someColor );

Access/change an object's color.

void move(double xOffset, double yOffset);

Move an object relative to its current position.

void moveTo(double x, double y);
void moveTo(Location someLocation); 

Move an object to point specified by coordinates.

void hide(); 
void show();
boolean isHidden();

Make an object invisible or visible on the display. Check if it is visible.

void removeFromCanvas();

Permanently remove an object from the canvas.

void addToCanvas (DrawingCanvas c);

Add the object to a canvas. This removes it from the current canvas because it can only be on one canvas at a time.

void sendForward();
void sendToFront();
void sendBackward();
void sendToBack();

Alter the stacking order that controls how overlapping objects appear.

Methods for Lines only

Location getStart()
Location getEnd()

Access the coordinates of the starting or ending point of the line.

void setStart(Location someLocation ); 
void setEnd(Location someLocation ); void setEndPoints(Location startLocation,  Location endLocation); void setEndPoints(double startX, double startY, double endX, double endY);

Change either or both of a line's end points.

Methods for Rectangles, Ovals, VisibleImage, and Text

double getX()
double getY()
Location getLocation()

Access one or both coordinates of the upper left corner of an object's bounding rectangle.

double getWidth()
double getHeight()

Access the dimensions of an object's bounding rectangle.

boolean overlaps (Drawable2DInterface item)

Returns true if the bounding rectangle of the item passed in overlaps with the bounding rectangle of the current object.

Methods for Rectangles, Ovals, and VisibleImages only

void setWidth(double width );
void setHeight(double height );

Change the width or height of a shape.

Methods for Text Objects only

void setText(String text);

Change the characters displayed.

void setFontSize(int pointSize );

Change the font size used.

void setBold();
void setItalic();
void setPlain();

Change the style in which text is displayed.

void setFont (Font someFont) 
void setFont (String fontName)

Change the font used.


Auxiliary Classes

Constructors for Auxilliary Classes

Color(int redness, 
      int greenness, 
      int blueness); 

Mix a new color. Parameter values are numbers between 0 and 255.

Location(double x, double y);

Build a coordinate pair object for the point (x,y).

RandomIntGenerator(int min, 
                   int max)

Builds a random number generator that returns numbers between min and max, inclusive.

Methods for Color Class

int getRed()
int getGreen()
int getBlue()

Access any of the color values associated with a Color.

Methods for Location Class

double getX()
double getY()

Access either of the elements of a coordinate pair.

Methods for RandomIntGenerator Class

int nextValue ()

Returns the next random number.