Class Canvas

java.lang.Object
  extended by Canvas

public class Canvas
extends java.lang.Object

Class Canvas - a class to allow for simple graphical drawing on a 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(java.lang.String title)
          Create a Canvas with default height, width and background color (300, 300, white).
 
Method Summary
 void drawFilledOval(int x1, int y1, int x2, int y2)
          Draws a filled oval on the Canvas.
 void drawFilledPolygon(int[] x, int[] y, int size)
          Draws a filled polygon on the Canvas.
 void drawFilledRectangle(int x1, int y1, int x2, int y2)
          Draws a filled rectangle on the Canvas.
 void drawLine(int x1, int y1, int x2, int y2)
          Draws a line on the Canvas.
 void drawOval(int x1, int y1, int x2, int y2)
          Draws an oval on the Canvas.
 void drawPolygon(int[] x, int[] y, int size)
          Draws a polygon on the Canvas.
 void drawRectangle(int x1, int y1, int x2, int y2)
          Draws a rectangle on the Canvas.
 void drawString(java.lang.String text, int x, int y)
          Draws a String on the Canvas.
 void erase()
          Erase the whole canvas.
 void eraseOval(int x1, int y1, int x2, int y2)
          Erases an oval on the Canvas.
 void eraseRectangle(int x1, int y1, int x2, int y2)
          Erases a rectangle on the Canvas.
 void eraseString(java.lang.String text, int x, int 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 setFont(java.awt.Font newFont)
          changes the current Font used on the Canvas
 void setFontSize(int 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(int width, int 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.
 void wait(int milliseconds)
          Waits for a specified number of milliseconds before finishing.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

canvas

protected Canvas.CanvasPane canvas
Constructor Detail

Canvas

public Canvas(java.lang.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(java.lang.String text,
                       int x,
                       int y)
Draws a String on the Canvas.

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

eraseString

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

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

drawLine

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

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

drawRectangle

public void drawRectangle(int x1,
                          int y1,
                          int x2,
                          int y2)
Draws a rectangle on the Canvas.

Parameters:
x1 - x co-ordinate of top left corner
y1 - y co-ordinate of top left corner
x2 - width
y2 - height

drawFilledRectangle

public void drawFilledRectangle(int x1,
                                int y1,
                                int x2,
                                int y2)
Draws a filled rectangle on the Canvas.

Parameters:
x1 - x co-ordinate of top left corner
y1 - y co-ordinate of top left corner
x2 - width
y2 - height

drawPolygon

public void drawPolygon(int[] x,
                        int[] y,
                        int size)
Draws a polygon on the Canvas.

Parameters:
x - array of x co-ordinates of polygon points
y - array of y co-ordinates of polygon points
size - the number of points (vertices) in the polygon

drawFilledPolygon

public void drawFilledPolygon(int[] x,
                              int[] y,
                              int size)
Draws a filled polygon on the Canvas.

Parameters:
x - array of x co-ordinates of polygon points
y - array of y co-ordinates of polygon points
size - the number of points (vertices) in the polygon

eraseRectangle

public void eraseRectangle(int x1,
                           int y1,
                           int x2,
                           int y2)
Erases a rectangle on the Canvas.

Parameters:
x1 - x co-ordinate of top left corner
y1 - y co-ordinate of top left corner
x2 - width
y2 - height

drawOval

public void drawOval(int x1,
                     int y1,
                     int x2,
                     int y2)
Draws an oval on the Canvas.

Parameters:
x1 - x co-ordinate of top left corner
y1 - y co-ordinate of top left corner
x2 - width
y2 - height

drawFilledOval

public void drawFilledOval(int x1,
                           int y1,
                           int x2,
                           int y2)
Draws a filled oval on the Canvas.

Parameters:
x1 - x co-ordinate of top left corner
y1 - y co-ordinate of top left corner
x2 - width
y2 - height

eraseOval

public void eraseOval(int x1,
                      int y1,
                      int x2,
                      int y2)
Erases an oval on the Canvas.

Parameters:
x1 - x co-ordinate of top left corner
y1 - y co-ordinate of top left corner
x2 - width
y2 - 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(int 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(int width,
                    int height)
Sets the size of the canvas.

Parameters:
width - new width
height - new height

wait

public void wait(int 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