comp100
Class DrawingCanvas

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Canvas
          extended bycomp100.DrawingCanvas
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable

public class DrawingCanvas
extends java.awt.Canvas

A DrawingCanvas is an area for drawing shapes, text, and images. It uses double buffering for smoother graphics.

It provides methods for


Field Summary
static int MaxX
          Maximum width of the canvas
static int MaxY
          Maximum height of the canvas
 
Constructor Summary
DrawingCanvas()
           
 
Method Summary
 void clear() 
clear(boolean redraw)
Clear the canvas area. With an argument of false, do not redisplay the canvas yet.
 void display()
Redisplay the canvas area, including all the shapes that have not yet been redisplayed .
 void drawLine(int x1, int y1, int x2, int y2)
drawLine(int x1, int y1, int x2, int y2, boolean redraw)
Draw a line between (x1, y1) and (x2, y2).
With a fifth argument of false, do not redisplay the canvas yet.
 void invertLine(int x1, int y1, int x2, int y2)
invertLine(int x1, int y1, int x2, int y2, boolean redraw)
Invert the line between (x1, y1) and (x2, y2). Inverting again will restore the original colours
With a fifth argument of false, do not redisplay the canvas yet.
 void drawRect(int x, int y, int width, int height)
drawRect(int x, int y, int width, int height, boolean redraw)
fillRect(int x, int y, int width, int height)
fillRect(int x, int y, int width, int height, boolean redraw)
Draw a rectangle (outline or filled) with left edge at x, top edge at y of width and height.
With a fifth argument of false, do not redisplay the canvas yet.
 void invertRect(int x, int y, int width, int height)
invertRect(int x, int y, int width, int height, boolean redraw)
Invert the rectangle outline with left edge at x, top edge at y of width and height. Inverting again will restore the original colours.
With a fifth argument of false, do not redisplay the canvas yet.
 void clearRect(int x, int y, int width, int height, boolean redraw)
clearRect(int x, int y, int width, int height)
Clear the rectangular region with left edge at x, top edge at y of width and height.
With a fifth argument of false, do not redisplay the canvas yet.
 void drawOval(int x, int y, int width, int height)
drawOval(int x, int y, int width, int height, boolean redraw)
fillOval(int x, int y, int width, int height, boolean redraw)
fillOval(int x, int y, int width, int height, boolean redraw)
Draw an oval (outline or filled) with left edge at x, top edge at y of width and height.
With a fifth argument of false, do not redisplay the canvas yet.
 void drawString(java.lang.String s, int x, int y)
drawString(java.lang.String s, int x, int y, boolean redraw)
Draw a string with its bottom left corner at (x1, y1).
With a fifth argument of false, do not redisplay the canvas yet.
 void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle, boolean redraw)
drawArc(int x, int y, int width, int height, int startAngle, int arcAngle)
fillArc(int x, int y, int width, int height, int startAngle, int arcAngle)
fillArc(int x, int y, int width, int height, int startAngle, int arcAngle, boolean redraw)
Draw an arc of an oval (outline or filled). The oval would have its left edge at x, top edge at y, of width and height. The arc begins at startAngle and extends for arcAngle degrees.
Angles are interpreted such that 0 degrees is at the 3 o'clock position.
With a seventh argument of false, do not redisplay the canvas yet.
 void drawImage(java.lang.String filename, int x, int y, int width, int height)
drawImage(java.lang.String filename, int x, int y, int width, int height, boolean redraw)
Load image from filename and draw it with left edge at x, top edge at y scaled to width and height.
With a fifth argument of false, do not redisplay the canvas yet.
 void setFontSize(int size)
Set the current font size
 void setColor(java.awt.Color c)
Set the current foreground color - the color that all subsequent shapes or text will be drawn
 java.awt.Graphics getBackingGraphics()
          Get the Graphics object that is the backing store of the image, so that programs can do more complicated operations on the image than are provided by this class.
 java.awt.Dimension getMaximumSize()
           
 java.awt.Dimension getPreferredSize()
           
 void paint(java.awt.Graphics g)
           
 void print(java.awt.Graphics g)
           
 void update(java.awt.Graphics g)
           
 void addNotify()
           

Field Detail

MaxX

public static final int MaxX
Maximum width of the canvas


MaxY

public static final int MaxY
Maximum height of the canvas

Constructor Detail

DrawingCanvas

public DrawingCanvas()
Method Detail

addNotify

public void addNotify()

print

public void print(java.awt.Graphics g)

paint

public void paint(java.awt.Graphics g)

setFontSize

public void setFontSize(int size)
Set the current font size


update

public void update(java.awt.Graphics g)

getPreferredSize

public java.awt.Dimension getPreferredSize()

getMaximumSize

public java.awt.Dimension getMaximumSize()

display

public void display()
Redisplay the canvas area, including all the shapes that have not yet been redisplayed .


display

public void display(int x,
                    int y,
                    int width,
                    int height)

getBackingGraphics

public java.awt.Graphics getBackingGraphics()
Get the Graphics object that is the backing store of the image, so that programs can do more complicated operations on the image than are provided by this class.
Standard usage would be to get the graphics object, call methods on it, and then call the display() method on the DrawingCanvas to update the visible imagewith the modifications.


clear

public void clear()
Clear the canvas area.


clear

public void clear(boolean redraw)
Clear the canvas area. With an argument of false, do not redisplay the canvas yet.


setColor

public void setColor(java.awt.Color c)
Set the current foreground color - the color that all subsequent shapes or text


drawLine

public void drawLine(int x1,
                     int y1,
                     int x2,
                     int y2)
Draw a line between (x1, y1) and (x2, y2).
With a fifth argument of false, do not redisplay the canvas yet.


drawLine

public void drawLine(int x1,
                     int y1,
                     int x2,
                     int y2,
                     boolean redraw)

drawRect

public void drawRect(int x,
                     int y,
                     int width,
                     int height)
Draw a rectangle (outline or filled) with left edge at x, top edge at y of width and height.
With a fifth argument of false, do not redisplay the canvas yet.


drawRect

public void drawRect(int x,
                     int y,
                     int width,
                     int height,
                     boolean redraw)

fillRect

public void fillRect(int x,
                     int y,
                     int width,
                     int height)

fillRect

public void fillRect(int x,
                     int y,
                     int width,
                     int height,
                     boolean redraw)

clearRect

public void clearRect(int x,
                      int y,
                      int width,
                      int height)
Clear the rectangular region with left edge at x, top edge at y of width and height.
With a fifth argument of false, do not redisplay the canvas yet.


clearRect

public void clearRect(int x,
                      int y,
                      int width,
                      int height,
                      boolean redraw)

drawString

public void drawString(java.lang.String s,
                       int x,
                       int y)
Draw a string with its bottom left corner at (x1, y1).
With a fifth argument of false, do not redisplay the canvas yet.


drawString

public void drawString(java.lang.String s,
                       int x,
                       int y,
                       boolean redraw)

drawOval

public void drawOval(int x,
                     int y,
                     int width,
                     int height)
Draw an oval (outline or filled) with left edge at x, top edge at y of width and height.
With a fifth argument of false, do not redisplay the canvas yet.


drawOval

public void drawOval(int x,
                     int y,
                     int width,
                     int height,
                     boolean redraw)

fillOval

public void fillOval(int x,
                     int y,
                     int width,
                     int height)

fillOval

public void fillOval(int x,
                     int y,
                     int width,
                     int height,
                     boolean redraw)

drawArc

public void drawArc(int x,
                    int y,
                    int width,
                    int height,
                    int startAngle,
                    int arcAngle)
Draw an arc of an oval (outline or filled) The left edge of the oval would be at x, top edge at y of width and height.The arc begins at startAngle and extends for arcAngle degrees.
Angles are interpreted such that 0 degrees is at the 3 o'clock position. A positive value indicates a counter-clockwise rotation while a negative value indicates a clockwise rotation.
With a fifth argument of false, do not redisplay the canvas yet.


drawArc

public void drawArc(int x,
                    int y,
                    int width,
                    int height,
                    int startAngle,
                    int arcAngle,
                    boolean redraw)

fillArc

public void fillArc(int x,
                    int y,
                    int width,
                    int height,
                    int startAngle,
                    int arcAngle)

fillArc

public void fillArc(int x,
                    int y,
                    int width,
                    int height,
                    int startAngle,
                    int arcAngle,
                    boolean redraw)

invertLine

public void invertLine(int x1,
                       int y1,
                       int x2,
                       int y2)
Invert the line between (x1, y1) and (x2, y2).
With a fifth argument of false, do not redisplay the canvas yet.


invertLine

public void invertLine(int x1,
                       int y1,
                       int x2,
                       int y2,
                       boolean redraw)

invertRect

public void invertRect(int x,
                       int y,
                       int width,
                       int height)
Invert the rectangular region with left edge at x, top edge at y of width and height.
With a fifth argument of false, do not redisplay the canvas yet.


invertRect

public void invertRect(int x,
                       int y,
                       int width,
                       int height,
                       boolean redraw)

drawImage

public void drawImage(java.lang.String filename,
                      int x,
                      int y,
                      int width,
                      int height)
Load the image from filename and draw it with left edge at x, top edge at y scaled to width and height.


drawImage

public void drawImage(java.lang.String filename,
                      int x,
                      int y,
                      int width,
                      int height,
                      boolean redraw)