Quick Summary of Graphic Objects and Methods

Constructors for Auxilliary Classes

new Color(redness, greenness, blueness); Mix a new color. Parameter values are numbers between 0 and 255.
new Location(x,y); Build a coordinate pair object for the point (x,y).

Accessor Methods for Auxilliary Classes

someColor.getRed()
someColor.getGreen()
someColor.getBlue()

Access any of the color values associated with a Color.
someLocation.getX()
someLocation.getY()

Access either of the elements of a coordinate pair.
someLocation.distanceTo(anotherLocation)
Determine the distance between two points.

Constructors for Graphic Objects

new FramedRect(x, y, width, height, canvas);
new FilledRect(x, y, width, height, canvas);
new FramedOval(x, y, width, height, canvas);
new FilledOval(x, y, width, height, canvas);

new FramedRect(corner1Location, corner2Location, canvas);
new FilledRect(corner1Location, corner2Location, canvas);
new FramedOval(corner1Location, corner2Location, canvas);
new FilledOval(corner1Location, corner2Location, canvas);

new FramedRect(cornerLocation, width, height, canvas);
new FilledRect(cornerLocation, width, height, canvas);
new FramedOval(cornerLocation, width, height, canvas);
new FilledOval(cornerLocation, width, height, canvas);

The parameters to a rectangle or oval constructor describe the rectangle bounding the object to be drawn. You 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.


new Line(startX, startY, endX, endY, canvas);
new Line(startLocation, endLocation, canvas);

A line is described by giving its end points.

new Text("some message", x, y, canvas);
new Text("some message", baseLocation, canvas);
The coordinates specify the leftmost point of the text's baseline.

Methods Available for All Graphic Objects

someObject.move(xOffset, yOffset);

Move an object relative to its current position.

someObject.moveTo(x, y);
someObject.moveTo(someLocation);
Move an object to point specified by coordinates.

someObject.contains(someLocation);
Determine if an object's bounding box contains a point.

someObject.hide();
someObject.show();
Make an object invisible or visible on the display.

someObject.removeFromCanvas();
Delete object from its canvas.

someObject.sendForward();
someObject.sendToFront();
someObject.sendBackward();
someObject.sendToBack();
Alter the stacking order that controls how overlapping objects appear.

someObject.getColor();
someObject.setColor(someColor);
Access or change an object's color.

Methods Available for All 2-D Graphic Objects (including Text, but not Line)

someObject.getX();
someObject.getY();
someObject.getLocation();

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

someObject.getWidth();
someObject.getHeight();
Access the dimensions of an object's bounding rectangle.

Methods Available for Resizable 2-D Graphic Objects (not Text)

someObject.setWidth(newWidth);
someObject.setheight(newHt);

Change the dimensions of an object's bounding rectangle.

Mutator Methods for Lines

someLine.setStart(x, y);
someLine.setStart(someLocation);
someLine.setEnd(x, y);
someLine.setEnd(someLocation);
someLine.setEndPoints(x1, y1, x2, y2);
someLine.setEndPoints(startLocation, endLocation);

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

Mutator Methods for Text Objects

someText.setText("new message");
Change the characters displayed.

someText.setFontSize(pointSize);
Change the font size used.

someText.setBold(true);
someText.setItalic(true);
someText.setPlain();
Change the style in which text is displayed.

someText.setFont(someFont)
Change the font used.