java.lang.Objectjava.awt.Component
java.awt.Canvas
comp100.DrawingCanvas
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 |
public static final int MaxX
public static final int MaxY
Constructor Detail |
public DrawingCanvas()
Method Detail |
public void addNotify()
public void print(java.awt.Graphics g)
public void paint(java.awt.Graphics g)
public void setFontSize(int size)
public void update(java.awt.Graphics g)
public java.awt.Dimension getPreferredSize()
public java.awt.Dimension getMaximumSize()
public void display()
public void display(int x, int y, int width, int height)
public java.awt.Graphics getBackingGraphics()
public void clear()
public void clear(boolean redraw)
public void setColor(java.awt.Color c)
public void drawLine(int x1, int y1, int x2, int y2)
public void drawLine(int x1, int y1, int x2, int y2, boolean redraw)
public void drawRect(int x, int y, int width, int height)
public void drawRect(int x, int y, int width, int height, boolean redraw)
public void fillRect(int x, int y, int width, int height)
public void fillRect(int x, int y, int width, int height, boolean redraw)
public void clearRect(int x, int y, int width, int height)
public void clearRect(int x, int y, int width, int height, boolean redraw)
public void drawString(java.lang.String s, int x, int y)
public void drawString(java.lang.String s, int x, int y, boolean redraw)
public void drawOval(int x, int y, int width, int height)
public void drawOval(int x, int y, int width, int height, boolean redraw)
public void fillOval(int x, int y, int width, int height)
public void fillOval(int x, int y, int width, int height, boolean redraw)
public void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle)
public void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle, boolean redraw)
public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle)
public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle, boolean redraw)
public void invertLine(int x1, int y1, int x2, int y2)
public void invertLine(int x1, int y1, int x2, int y2, boolean redraw)
public void invertRect(int x, int y, int width, int height)
public void invertRect(int x, int y, int width, int height, boolean redraw)
public void drawImage(java.lang.String filename, int x, int y, int width, int height)
public void drawImage(java.lang.String filename, int x, int y, int width, int height, boolean redraw)