Class ShapeCanvas

java.lang.Object
  extended by ShapeCanvas

public class ShapeCanvas
extends java.lang.Object

A Canvas class for doing basic graphical drawing. This particular canvas focuses on drawing shapes that have been "added" to it.

Version:
Jan 2013
Author:
Joel Ross, based on class by Michael Kolling and Bruce Quig

Constructor Summary
ShapeCanvas(java.lang.String title)
          Create a Canvas with default height and width (400 x 400)
ShapeCanvas(java.lang.String title, int width, int height)
          Create a Canvas.
 
Method Summary
 void addShape(DrawableShape shape)
          Adds a Shape to the canvas.
static void main(java.lang.String[] args)
           
 void refresh()
          A method that refreshes what is displayed on the canvas.
 void removeShape(DrawableShape shape)
          Removes a Shape from the canvas.
 void toggleAutomaticRefresh()
          Toggles whether the canvas should automatically refresh.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ShapeCanvas

public ShapeCanvas(java.lang.String title)
Create a Canvas with default height and width (400 x 400)

Parameters:
title - title to appear in Canvas Frame

ShapeCanvas

public ShapeCanvas(java.lang.String title,
                   int width,
                   int height)
Create a Canvas. Makes the Canvas visible when it is constructed

Parameters:
title - title to appear in Canvas Frame
width - the desired width for the canvas
height - the desired height for the canvas
Method Detail

addShape

public void addShape(DrawableShape shape)
Adds a Shape to the canvas. Any changes to those shapes will be reflected on the drawn canvas.

Parameters:
shape - the Shape to add to the canvas

main

public static void main(java.lang.String[] args)

refresh

public void refresh()
A method that refreshes what is displayed on the canvas. This method redraws the shapes on the canvas.


removeShape

public void removeShape(DrawableShape shape)
Removes a Shape from the canvas. It will no longer be shown.

Parameters:
shape - the Shape to remove from the canvas

toggleAutomaticRefresh

public void toggleAutomaticRefresh()
Toggles whether the canvas should automatically refresh. On by default.