Class PaintCanvas

java.lang.Object
   |
   +----java.awt.Component
           |
           +----java.awt.Canvas
                   |
                   +----PaintCanvas

public class PaintCanvas
extends Canvas

Variable Index

 o bounds
 o intHeight
 o intWidth
 o needRealloc
 o offscreenGraphics
 o offscreenImage
 o penColor
 o pixmap
 o screenLock
 o theApplet
 o theFont

Constructor Index

 o PaintCanvas()

Method Index

 o clear()
This method clears the canvas to white
 o draw3DRect(int, int, int, int, boolean)
This method performs a draw3DRect, just like the Graphics object method.
 o drawArc(int, int, int, int, int, int)
This method performs a drawArc, just like the Graphics object method.
 o drawImage(Image, int, int)
This method performs a drawImage, just like the Graphics object method.
 o drawImage(Image, int, int, int, int)
This method performs a drawImage, just like the Graphics object method.
 o drawImage(Image, int, int, int, int, int, int, int, int)
This method performs a drawImage, just like the Graphics object method.
 o drawLine(int, int, int, int)
This method performs a drawLine, just like the Graphics object method.
 o drawOval(int, int, int, int)
This method performs a drawOval, just like the Graphics object method.
 o drawPolygon(int[], int[], int)
This method performs a drawPolygon, just like the Graphics object method.
 o drawPolygon(Polygon)
This method performs a drawPolygon, just like the Graphics object method.
 o drawPolyline(int[], int[], int)
This method performs a drawPolyline, just like the Graphics object method.
 o drawRect(int, int, int, int)
This method performs a drawRect, just like the Graphics object method.
 o drawRoundRect(int, int, int, int, int, int)
This method performs a drawRoundRect, just like the Graphics object method.
 o drawString(String, int, int)
This method performs a drawString, just like the Graphics object method.
 o fill3DRect(int, int, int, int, boolean)
This method performs a fill3DRect, just like the Graphics object method.
 o fillArc(int, int, int, int, int, int)
This method performs a fillArc, just like the Graphics object method.
 o fillOval(int, int, int, int)
This method performs a fillOval, just like the Graphics object method.
 o fillPolygon(int[], int[], int)
This method performs a fillPolygon, just like the Graphics object method.
 o fillPolygon(Polygon)
This method performs a fillPolygon, just like the Graphics object method.
 o fillRect(int, int, int, int)
This method performs a fillRect, just like the Graphics object method.
 o fillRoundRect(int, int, int, int, int, int)
This method performs a fillRoundRect, just like the Graphics object method.
 o getColor()
This method returns the current pen color of this PaintCanvas
 o getFont()
This method returns the font currently set to draw text in this PaintCanvas.
 o getFontMetrics()
This method returns a FontMetrics object for the font currently in use by this PaintCanvas object.
 o getImage()
This method returns an Image object representing the current state of this PaintCanvas
 o getPixelBlue(int, int)
This method returns the blue component for the pixel at the specified coordinates in the canvas, or 127 if coordinates are out of bounds.
 o getPixelColor(int, int)
This method returns the color of the pixel at the specified coordinates in the canvas, or medium gray (127,127,127) if coordinates are out of bounds.
 o getPixelGreen(int, int)
This method returns the green component for the pixel at the specified coordinates in the canvas, or 127 if coordinates are out of bounds.
 o getPixelRed(int, int)
This method returns the red component for the pixel at the specified coordinates in the canvas, or 127 if coordinates are out of bounds.
 o getSize()
This method overrides the built-in getSize method
 o isScreenLocked()
This method returns whether the screen is currently locked or not.
 o lockScreen()
This method locks the onscreen graphics area, so that drawing calls will not appear on the screen until repaint is called.
 o paint(Graphics)
 o paintPixel(int, int)
This method sets the color of the pixel at the specified coordinates to the current pen color of this PaintCanvas.
 o rescanPixmap()
 o setApplet(Applet)
Class method used to set up an applet to use for offscreen image creation.
 o setBounds(int, int, int, int)
This method overrides the built-in setBounds method
 o setColor(Color)
This method sets the pen color of this PaintCanvas
 o setFont(Font)
This method sets the font that will be used by this PaintCanvas to draw text.
 o setPixel(int, int, Color)
This method sets the color of the pixel at the specified coordinates to the specified color.
 o setPixmapBlue(int, int, int)
 o setPixmapColor(int, int, Color)
 o setPixmapGreen(int, int, int)
 o setPixmapRed(int, int, int)
 o setSize(int, int)
This method overrides the built-in setSize method
 o unlockScreen()
This method unlocks the onscreen drawing area so that any subsequent drawing calls will appear on the screen immediately.
 o update(Graphics)
This method overrides the built-in update method.

Variables

 o offscreenImage
 protected Image offscreenImage
 o offscreenGraphics
 protected Graphics offscreenGraphics
 o pixmap
 protected int pixmap[]
 o bounds
 protected Dimension bounds
 o needRealloc
 protected boolean needRealloc
 o penColor
 protected Color penColor
 o screenLock
 protected boolean screenLock
 o theFont
 protected Font theFont
 o intWidth
 protected int intWidth
 o intHeight
 protected int intHeight
 o theApplet
 protected static Applet theApplet

Constructors

 o PaintCanvas
 public PaintCanvas()

Methods

 o setApplet
 public static void setApplet(Applet app)
Class method used to set up an applet to use for offscreen image creation. This is necessary when you want to create and use a PaintCanvas that has no on-screen representation (i.e., one that is never added to another component). This will be the case when using a PaintCanvas as a temporary offscreen buffer of some sort.

Returns:
None
 o getImage
 public Image getImage()
This method returns an Image object representing the current state of this PaintCanvas

Returns:
Image -- the image
 o clear
 public void clear()
This method clears the canvas to white

Returns:
None
 o lockScreen
 public void lockScreen()
This method locks the onscreen graphics area, so that drawing calls will not appear on the screen until repaint is called. Reversed by unlockScreen.

Returns:
None
 o unlockScreen
 public void unlockScreen()
This method unlocks the onscreen drawing area so that any subsequent drawing calls will appear on the screen immediately.

Returns:
None
 o isScreenLocked
 public boolean isScreenLocked()
This method returns whether the screen is currently locked or not.

Returns:
boolean -- true is locked, false if not
 o setPixel
 public void setPixel(int x,
                      int y,
                      Color c)
This method sets the color of the pixel at the specified coordinates to the specified color.

Parameters:
int - x coordinate
int - y coordinate
Color - the color to set the pixel to
Returns:
None
 o paintPixel
 public void paintPixel(int x,
                        int y)
This method sets the color of the pixel at the specified coordinates to the current pen color of this PaintCanvas.

Parameters:
int - x coordinate
int - y coordinate
Returns:
None
 o getPixelRed
 public int getPixelRed(int x,
                        int y)
This method returns the red component for the pixel at the specified coordinates in the canvas, or 127 if coordinates are out of bounds.

Parameters:
int - x coord
int - y coord
Returns:
int -- the red component
 o getPixelGreen
 public int getPixelGreen(int x,
                          int y)
This method returns the green component for the pixel at the specified coordinates in the canvas, or 127 if coordinates are out of bounds.

Parameters:
int - x coord
int - y coord
Returns:
int -- the green component
 o getPixelBlue
 public int getPixelBlue(int x,
                         int y)
This method returns the blue component for the pixel at the specified coordinates in the canvas, or 127 if coordinates are out of bounds.

Parameters:
int - x coord
int - y coord
Returns:
int -- the blue component
 o getPixelColor
 public Color getPixelColor(int x,
                            int y)
This method returns the color of the pixel at the specified coordinates in the canvas, or medium gray (127,127,127) if coordinates are out of bounds.

Parameters:
int - x coord
int - y coord
Returns:
Color -- the pixel's color
 o setColor
 public void setColor(Color c)
This method sets the pen color of this PaintCanvas

Parameters:
Color - the new pen color
Returns:
None
 o getColor
 public Color getColor()
This method returns the current pen color of this PaintCanvas

Returns:
Color -- current pen color
 o fillArc
 public void fillArc(int x,
                     int y,
                     int width,
                     int height,
                     int startAngle,
                     int arcAngle)
This method performs a fillArc, just like the Graphics object method.

Parameters:
int - x coordinate
int - y coordinate
int - width
int - height
int - starting angle
int - arc angle
Returns:
None
 o drawArc
 public void drawArc(int x,
                     int y,
                     int width,
                     int height,
                     int startAngle,
                     int arcAngle)
This method performs a drawArc, just like the Graphics object method.

Parameters:
int - x coordinate
int - y coordinate
int - width
int - height
int - starting angle
int - arc angle
Returns:
None
 o fillPolygon
 public void fillPolygon(int xPoints[],
                         int yPoints[],
                         int nPoints)
This method performs a fillPolygon, just like the Graphics object method.

Parameters:
int[] - x points
int[] - y points
int - number of points
Returns:
None
 o fillPolygon
 public void fillPolygon(Polygon p)
This method performs a fillPolygon, just like the Graphics object method.

Parameters:
Polygon - the polygon to fill
Returns:
None
 o drawPolygon
 public void drawPolygon(int xPoints[],
                         int yPoints[],
                         int nPoints)
This method performs a drawPolygon, just like the Graphics object method.

Parameters:
int[] - x points
int[] - y points
int - number of points
Returns:
None
 o drawPolygon
 public void drawPolygon(Polygon p)
This method performs a drawPolygon, just like the Graphics object method.

Parameters:
Polygon - the polygon to draw
Returns:
None
 o drawPolyline
 public void drawPolyline(int xPoints[],
                          int yPoints[],
                          int nPoints)
This method performs a drawPolyline, just like the Graphics object method.

Parameters:
int[] - x points
int[] - y points
int - number of points
Returns:
None
 o fillRect
 public void fillRect(int x,
                      int y,
                      int width,
                      int height)
This method performs a fillRect, just like the Graphics object method.

Parameters:
int - x coordinate
int - y coordinate
int - width
int - height
Returns:
None
 o drawRect
 public void drawRect(int x,
                      int y,
                      int width,
                      int height)
This method performs a drawRect, just like the Graphics object method.

Parameters:
int - x coordinate
int - y coordinate
int - width
int - height
Returns:
None
 o fill3DRect
 public void fill3DRect(int x,
                        int y,
                        int width,
                        int height,
                        boolean raised)
This method performs a fill3DRect, just like the Graphics object method.

Parameters:
int - x coordinate
int - y coordinate
int - width
int - height
boolean - raised or indented
Returns:
None
 o draw3DRect
 public void draw3DRect(int x,
                        int y,
                        int width,
                        int height,
                        boolean raised)
This method performs a draw3DRect, just like the Graphics object method.

Parameters:
int - x coordinate
int - y coordinate
int - width
int - height
boolean - raised or indented
Returns:
None
 o fillOval
 public void fillOval(int x,
                      int y,
                      int width,
                      int height)
This method performs a fillOval, just like the Graphics object method.

Parameters:
int - x coordinate
int - y coordinate
int - width
int - height
Returns:
None
 o drawOval
 public void drawOval(int x,
                      int y,
                      int width,
                      int height)
This method performs a drawOval, just like the Graphics object method.

Parameters:
int - x coordinate
int - y coordinate
int - width
int - height
Returns:
None
 o fillRoundRect
 public void fillRoundRect(int x,
                           int y,
                           int width,
                           int height,
                           int arcWidth,
                           int arcHeight)
This method performs a fillRoundRect, just like the Graphics object method.

Parameters:
int - x coordinate
int - y coordinate
int - width
int - height
int - corner arc width
int - corner arc height
Returns:
None
 o drawRoundRect
 public void drawRoundRect(int x,
                           int y,
                           int width,
                           int height,
                           int arcWidth,
                           int arcHeight)
This method performs a drawRoundRect, just like the Graphics object method.

Parameters:
int - x coordinate
int - y coordinate
int - width
int - height
int - corner arc width
int - corner arc height
Returns:
None
 o drawLine
 public void drawLine(int x1,
                      int y1,
                      int x2,
                      int y2)
This method performs a drawLine, just like the Graphics object method.

Parameters:
int - starting x coordinate
int - starting y coordinate
int - ending x coordinate
int - ending y coordinate
Returns:
None
 o drawImage
 public void drawImage(Image img,
                       int x,
                       int y)
This method performs a drawImage, just like the Graphics object method.

Parameters:
Image - the image to draw
int - left x coordinate
int - top y coordinate
Returns:
None
 o drawImage
 public void drawImage(Image img,
                       int x,
                       int y,
                       int width,
                       int height)
This method performs a drawImage, just like the Graphics object method. Performs scaling.

Parameters:
Image - the image to draw
int - left x coordinate
int - top y coordinate
int - width to draw at
int - height to draw at
Returns:
None
 o drawImage
 public void drawImage(Image img,
                       int dx1,
                       int dy1,
                       int dx2,
                       int dy2,
                       int sx1,
                       int sy1,
                       int sx2,
                       int sy2)
This method performs a drawImage, just like the Graphics object method. Performs scaling and draws from one rect to another.

Parameters:
Image - the image to draw
int - dest left coord
int - dest top coord
int - dest right coord
int - dest bottom coord
int - src left coord
int - src top coord
int - src right coord
int - src bottom coord
Returns:
None
 o drawString
 public void drawString(String s,
                        int x,
                        int y)
This method performs a drawString, just like the Graphics object method.

Parameters:
String - string to draw
int - starting x coord
int - starting y coord
Returns:
None
 o setFont
 public void setFont(Font f)
This method sets the font that will be used by this PaintCanvas to draw text.

Parameters:
Font - the new font
Returns:
None
Overrides:
setFont in class Component
 o getFont
 public Font getFont()
This method returns the font currently set to draw text in this PaintCanvas.

Returns:
Font -- the current font
Overrides:
getFont in class Component
 o getFontMetrics
 public FontMetrics getFontMetrics()
This method returns a FontMetrics object for the font currently in use by this PaintCanvas object.

Returns:
FontMetrics -- a FontMetrics object for the font currently in use
 o getSize
 public Dimension getSize()
This method overrides the built-in getSize method

Returns:
Dimension -- the size of this PaintCanvas
Overrides:
getSize in class Component
 o setSize
 public void setSize(int width,
                     int height)
This method overrides the built-in setSize method

Parameters:
int - width
int - height
Returns:
int -- None
Overrides:
setSize in class Component
 o setBounds
 public void setBounds(int x,
                       int y,
                       int width,
                       int height)
This method overrides the built-in setBounds method

Parameters:
int - x coord
int - y coord
int - width
int - height
Returns:
int -- None
Overrides:
setBounds in class Component
 o update
 public void update(Graphics g)
This method overrides the built-in update method. You should not need to call this method directly.

Parameters:
Graphics - graphics context to draw to
Returns:
int -- None
Overrides:
update in class Component
 o paint
 public void paint(Graphics g)
Overrides:
paint in class Canvas
 o setPixmapRed
 protected void setPixmapRed(int x,
                             int y,
                             int red)
 o setPixmapGreen
 protected void setPixmapGreen(int x,
                               int y,
                               int green)
 o setPixmapBlue
 protected void setPixmapBlue(int x,
                              int y,
                              int blue)
 o setPixmapColor
 protected void setPixmapColor(int x,
                               int y,
                               Color c)
 o rescanPixmap
 public void rescanPixmap()