Class PaintCanvas
java.lang.Object
|
+----java.awt.Component
|
+----java.awt.Canvas
|
+----PaintCanvas
- public class PaintCanvas
- extends Canvas
-
bounds
-
-
intHeight
-
-
intWidth
-
-
needRealloc
-
-
offscreenGraphics
-
-
offscreenImage
-
-
penColor
-
-
pixmap
-
-
screenLock
-
-
theApplet
-
-
theFont
-
-
PaintCanvas()
-
-
clear()
- This method clears the canvas to white
-
draw3DRect(int, int, int, int, boolean)
- This method performs a draw3DRect, just like the Graphics object
method.
-
drawArc(int, int, int, int, int, int)
- This method performs a drawArc, just like the Graphics object
method.
-
drawImage(Image, int, int)
- This method performs a drawImage, just like the Graphics object
method.
-
drawImage(Image, int, int, int, int)
- This method performs a drawImage, just like the Graphics object
method.
-
drawImage(Image, int, int, int, int, int, int, int, int)
- This method performs a drawImage, just like the Graphics object
method.
-
drawLine(int, int, int, int)
- This method performs a drawLine, just like the Graphics object
method.
-
drawOval(int, int, int, int)
- This method performs a drawOval, just like the Graphics object
method.
-
drawPolygon(int[], int[], int)
- This method performs a drawPolygon, just like the Graphics object
method.
-
drawPolygon(Polygon)
- This method performs a drawPolygon, just like the Graphics object
method.
-
drawPolyline(int[], int[], int)
- This method performs a drawPolyline, just like the Graphics object
method.
-
drawRect(int, int, int, int)
- This method performs a drawRect, just like the Graphics object
method.
-
drawRoundRect(int, int, int, int, int, int)
- This method performs a drawRoundRect, just like the Graphics object
method.
-
drawString(String, int, int)
- This method performs a drawString, just like the Graphics object
method.
-
fill3DRect(int, int, int, int, boolean)
- This method performs a fill3DRect, just like the Graphics object
method.
-
fillArc(int, int, int, int, int, int)
- This method performs a fillArc, just like the Graphics object
method.
-
fillOval(int, int, int, int)
- This method performs a fillOval, just like the Graphics object
method.
-
fillPolygon(int[], int[], int)
- This method performs a fillPolygon, just like the Graphics object
method.
-
fillPolygon(Polygon)
- This method performs a fillPolygon, just like the Graphics object
method.
-
fillRect(int, int, int, int)
- This method performs a fillRect, just like the Graphics object
method.
-
fillRoundRect(int, int, int, int, int, int)
- This method performs a fillRoundRect, just like the Graphics object
method.
-
getColor()
- This method returns the current pen color of this PaintCanvas
-
getFont()
- This method returns the font currently set to draw text in
this PaintCanvas.
-
getFontMetrics()
- This method returns a FontMetrics object for the font
currently in use by this PaintCanvas object.
-
getImage()
- This method returns an Image object representing the current
state of this PaintCanvas
-
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.
-
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.
-
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.
-
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.
-
getSize()
- This method overrides the built-in getSize method
-
isScreenLocked()
- This method returns whether the screen is currently locked
or not.
-
lockScreen()
- This method locks the onscreen graphics area, so that
drawing calls will not appear on the screen until repaint
is called.
-
paint(Graphics)
-
-
paintPixel(int, int)
- This method sets the color of the pixel at the specified
coordinates to the current pen color of this PaintCanvas.
-
rescanPixmap()
-
-
setApplet(Applet)
- Class method used to set up an applet to use for offscreen
image creation.
-
setBounds(int, int, int, int)
- This method overrides the built-in setBounds method
-
setColor(Color)
- This method sets the pen color of this PaintCanvas
-
setFont(Font)
- This method sets the font that will be used by this
PaintCanvas to draw text.
-
setPixel(int, int, Color)
- This method sets the color of the pixel at the specified
coordinates to the specified color.
-
setPixmapBlue(int, int, int)
-
-
setPixmapColor(int, int, Color)
-
-
setPixmapGreen(int, int, int)
-
-
setPixmapRed(int, int, int)
-
-
setSize(int, int)
- This method overrides the built-in setSize method
-
unlockScreen()
- This method unlocks the onscreen drawing area so that any
subsequent drawing calls will appear on the screen
immediately.
-
update(Graphics)
- This method overrides the built-in update method.
offscreenImage
protected Image offscreenImage
offscreenGraphics
protected Graphics offscreenGraphics
pixmap
protected int pixmap[]
bounds
protected Dimension bounds
needRealloc
protected boolean needRealloc
penColor
protected Color penColor
screenLock
protected boolean screenLock
theFont
protected Font theFont
intWidth
protected int intWidth
intHeight
protected int intHeight
theApplet
protected static Applet theApplet
PaintCanvas
public PaintCanvas()
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
getImage
public Image getImage()
- This method returns an Image object representing the current
state of this PaintCanvas
- Returns:
- Image -- the image
clear
public void clear()
- This method clears the canvas to white
- Returns:
- None
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
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
isScreenLocked
public boolean isScreenLocked()
- This method returns whether the screen is currently locked
or not.
- Returns:
- boolean -- true is locked, false if not
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
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
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
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
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
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
setColor
public void setColor(Color c)
- This method sets the pen color of this PaintCanvas
- Parameters:
- Color - the new pen color
- Returns:
- None
getColor
public Color getColor()
- This method returns the current pen color of this PaintCanvas
- Returns:
- Color -- current pen color
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
getSize
public Dimension getSize()
- This method overrides the built-in getSize method
- Returns:
- Dimension -- the size of this PaintCanvas
- Overrides:
- getSize in class Component
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
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
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
paint
public void paint(Graphics g)
- Overrides:
- paint in class Canvas
setPixmapRed
protected void setPixmapRed(int x,
int y,
int red)
setPixmapGreen
protected void setPixmapGreen(int x,
int y,
int green)
setPixmapBlue
protected void setPixmapBlue(int x,
int y,
int blue)
setPixmapColor
protected void setPixmapColor(int x,
int y,
Color c)
rescanPixmap
public void rescanPixmap()