Class Canvas

Object
  extended by Canvas

public class Canvas
extends Object

Class Canvas - a class to allow for simple graphical drawing on a canvas. ---> This is the primitives-free version of Canvas! <---


Nested Class Summary
protected  class Canvas.CanvasPane
          Nested class CanvasPane - the actual canvas component contained in the Canvas frame.
 
Field Summary
protected  Canvas.CanvasPane canvas
           
 
Constructor Summary
Canvas()
          Create a Canvas with default title, height, width and background color ("Canvas", 300, 300, white).
Canvas(String title)
          Create a Canvas with default height, width and background color (300, 300, white).
 
Method Summary
 void drawFilledOval(Integer x, Integer y, Integer width, Integer height)
          Draws a filled oval on the Canvas.
 void drawFilledPolygon(Integer[] xs, Integer[] ys, Integer size)
          Draws a filled polygon on the Canvas.
 void drawFilledRectangle(Integer x, Integer y, Integer width, Integer height)
          Draws a filled rectangle on the Canvas.
 void drawLine(Integer x1, Integer y1, Integer x2, Integer y2)
          Draws a line on the Canvas.
 void drawOval(Integer x, Integer y, Integer width, Integer height)
          Draws an oval on the Canvas.
 void drawPolygon(Integer[] xs, Integer[] ys, Integer size)
          Draws a polygon on the Canvas.
 void drawRectangle(Integer x, Integer y, Integer width, Integer height)
          Draws a rectangle on the Canvas.
 void drawString(String text, Integer x, Integer y)
          Draws a String on the Canvas.
 void erase()
          Erase the whole canvas.
 void eraseFilledOval(Integer x, Integer y, Integer width, Integer height)
          Erases a filled oval on the Canvas.
 void eraseFilledRectangle(Integer x, Integer y, Integer width, Integer height)
          Erases a filled rectangle on the Canvas.
 void eraseOval(Integer x, Integer y, Integer width, Integer height)
          Erases an oval on the Canvas.
 void eraseRectangle(Integer x, Integer y, Integer width, Integer height)
          Erases a rectangle on the Canvas.
 void eraseString(String text, Integer x, Integer y)
          Erases a String on the Canvas.
 void fillBackground(java.awt.Color newColor)
          Fills in the Canvas (background) with the specified color.
 java.awt.Font getFont()
          Returns the current font of the canvas.
 java.awt.Color getInkColor()
          Returns the current pen color.
 Boolean isVisible()
          Provide information on visibility of the Canvas.
 void pause(Integer milliseconds)
          Waits for a specified number of milliseconds before finishing.
 void setFont(java.awt.Font newFont)
          changes the current Font used on the Canvas
 void setFontSize(Integer newSize)
          Sets the point size of the current font to the specified value.
 void setInkColor(java.awt.Color newColor)
          Sets the "pen" (outline) color for the Canvas.
 void setSize(Integer width, Integer height)
          Sets the size of the canvas.
 void setVisible(Boolean visible)
          Set the canvas visibility and brings canvas to the front of screen when made visible.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

canvas

protected Canvas.CanvasPane canvas
Constructor Detail

Canvas

public Canvas(String title)
Create a Canvas with default height, width and background color (300, 300, white).

Parameters:
title - title to appear in Canvas Frame

Canvas

public Canvas()
Create a Canvas with default title, height, width and background color ("Canvas", 300, 300, white).

Method Detail

setInkColor

public void setInkColor(java.awt.Color newColor)
Sets the "pen" (outline) color for the Canvas.

Parameters:
newColor - The color to which to set the pen/drawing tool.

getInkColor

public java.awt.Color getInkColor()
Returns the current pen color.


setVisible

public void setVisible(Boolean visible)
Set the canvas visibility and brings canvas to the front of screen when made visible. This method can also be used to bring an already visible canvas to the front of other windows.

Parameters:
visible - Boolean value representing the desired visibility of the canvas (true or false)

isVisible

public Boolean isVisible()
Provide information on visibility of the Canvas.

Returns:
true if canvas is visible, false otherwise

erase

public void erase()
Erase the whole canvas.


drawString

public void drawString(String text,
                       Integer x,
                       Integer y)
Draws a String on the Canvas.

Parameters:
text - the String to be displayed
x - x coordinate for text placement
y - y coordinate for text placement

eraseString

public void eraseString(String text,
                        Integer x,
                        Integer y)
Erases a String on the Canvas.

Parameters:
text - the String to be displayed
x - x coordinate for text placement
y - y coordinate for text placement

drawLine

public void drawLine(Integer x1,
                     Integer y1,
                     Integer x2,
                     Integer y2)
Draws a line on the Canvas.

Parameters:
x1 - x coordinate of start of line
y1 - y coordinate of start of line
x2 - x coordinate of end of line
y2 - y coordinate of end of line

drawRectangle

public void drawRectangle(Integer x,
                          Integer y,
                          Integer width,
                          Integer height)
Draws a rectangle on the Canvas.

Parameters:
x - x coordinate of top left corner
y - y coordinate of top left corner
width - width
height - height

drawFilledRectangle

public void drawFilledRectangle(Integer x,
                                Integer y,
                                Integer width,
                                Integer height)
Draws a filled rectangle on the Canvas.

Parameters:
x - x coordinate of top left corner
y - y coordinate of top left corner
width - width
height - height

drawPolygon

public void drawPolygon(Integer[] xs,
                        Integer[] ys,
                        Integer size)
Draws a polygon on the Canvas.

Parameters:
xs - array of x coordinates of polygon points
ys - array of y coordinates of polygon points
size - the number of points (vertices) in the polygon

drawFilledPolygon

public void drawFilledPolygon(Integer[] xs,
                              Integer[] ys,
                              Integer size)
Draws a filled polygon on the Canvas.

Parameters:
xs - array of x coordinates of polygon points
ys - array of y coordinates of polygon points
size - the number of points (vertices) in the polygon

eraseRectangle

public void eraseRectangle(Integer x,
                           Integer y,
                           Integer width,
                           Integer height)
Erases a rectangle on the Canvas.

Parameters:
x - x coordinate of top left corner
y - y coordinate of top left corner
width - width
height - height

eraseFilledRectangle

public void eraseFilledRectangle(Integer x,
                                 Integer y,
                                 Integer width,
                                 Integer height)
Erases a filled rectangle on the Canvas.

Parameters:
x - x coordinate of top left corner
y - y coordinate of top left corner
width - width
height - height

drawOval

public void drawOval(Integer x,
                     Integer y,
                     Integer width,
                     Integer height)
Draws an oval on the Canvas.

Parameters:
x - x coordinate of top left corner
y - y coordinate of top left corner
width - width
height - height

drawFilledOval

public void drawFilledOval(Integer x,
                           Integer y,
                           Integer width,
                           Integer height)
Draws a filled oval on the Canvas.

Parameters:
x - x coordinate of top left corner
y - y coordinate of top left corner
width - width
height - height

eraseOval

public void eraseOval(Integer x,
                      Integer y,
                      Integer width,
                      Integer height)
Erases an oval on the Canvas.

Parameters:
x - x coordinate of top left corner
y - y coordinate of top left corner
width - width
height - height

eraseFilledOval

public void eraseFilledOval(Integer x,
                            Integer y,
                            Integer width,
                            Integer height)
Erases a filled oval on the Canvas.

Parameters:
x - x coordinate of top left corner
y - y coordinate of top left corner
width - width
height - height

fillBackground

public void fillBackground(java.awt.Color newColor)
Fills in the Canvas (background) with the specified color.

Parameters:
newColor - the new color for the background of the Canvas

setFont

public void setFont(java.awt.Font newFont)
changes the current Font used on the Canvas

Parameters:
newFont - new font to be used for String output

getFont

public java.awt.Font getFont()
Returns the current font of the canvas.

Returns:
the font currently in use

setFontSize

public void setFontSize(Integer newSize)
Sets the point size of the current font to the specified value. The style and font family remain the same.

Parameters:
newSize - the new point size

setSize

public void setSize(Integer width,
                    Integer height)
Sets the size of the canvas.

Parameters:
width - new width
height - new height

pause

public void pause(Integer milliseconds)
Waits for a specified number of milliseconds before finishing. This provides an easy way to specify a small delay which can be used when producing animations.

Parameters:
milliseconds - the number