java.lang.ObjectCanvas
Class Canvas - a class to allow for simple graphical drawing on a canvas.
Constructor Summary | |
Canvas(java.lang.String title)
Create a Canvas with default height, width and background color (300, 300, white). |
|
Canvas(java.lang.String title,
int width,
int height)
Create a Canvas with default background color (white). |
|
Canvas(java.lang.String title,
int width,
int height,
java.awt.Color bgColor)
Create a Canvas. |
Method Summary | |
void |
draw(java.awt.Shape shape)
Draw the outline of a given shape onto the canvas. |
boolean |
drawImage(java.awt.Image image,
int x,
int y)
Draws an image onto the canvas. |
void |
drawLine(int x1,
int y1,
int x2,
int y2)
Draws a line 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 |
erase(java.awt.Shape shape)
Erase a given shape's interior on the screen. |
void |
eraseCircle(int xPos,
int yPos,
int diameter)
Erase the internal dimensions of the given circle. |
void |
eraseOutline(java.awt.Shape shape)
Erases a given shape's outline on the screen. |
void |
eraseRectangle(int xPos,
int yPos,
int width,
int height)
Erase the internal dimensions of the given rectangle. |
void |
eraseString(java.lang.String text,
int x,
int y)
Erases a String on the Canvas. |
void |
fill(java.awt.Shape shape)
Fill the internal dimensions of a given shape with the current foreground color of the canvas. |
void |
fillCircle(int xPos,
int yPos,
int diameter)
Fill the internal dimensions of the given circle with the current foreground color of the canvas. |
void |
fillRectangle(int xPos,
int yPos,
int width,
int height)
Fill the internal dimensions of the given rectangle with the current foreground color of the canvas. |
java.awt.Color |
getBackgroundColor()
Returns the current color of the background |
java.awt.Font |
getFont()
Returns the current font of the canvas. |
java.awt.Color |
getForegroundColor()
Returns the current color of the foreground. |
java.awt.Dimension |
getSize()
Returns the size of the canvas. |
boolean |
isVisible()
Provide information on visibility of the Canvas. |
void |
setBackgroundColor(java.awt.Color newColor)
Sets the background color of the Canvas. |
void |
setFont(java.awt.Font newFont)
changes the current Font used on the Canvas |
void |
setForegroundColor(java.awt.Color newColor)
Sets the foreground color of 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 |
Constructor Detail |
public Canvas(java.lang.String title)
title
- title to appear in Canvas Framepublic Canvas(java.lang.String title, int width, int height)
title
- title to appear in Canvas Framewidth
- the desired width for the canvasheight
- the desired height for the canvaspublic Canvas(java.lang.String title, int width, int height, java.awt.Color bgColor)
title
- title to appear in Canvas Framewidth
- the desired width for the canvasheight
- the desired height for the canvasMethod Detail |
public void draw(java.awt.Shape shape)
shape
- the shape object to be drawn on the canvaspublic boolean drawImage(java.awt.Image image, int x, int y)
image
- the Image object to be displayedx
- x co-ordinate for Image placementy
- y co-ordinate for Image placement
public void drawLine(int x1, int y1, int x2, int y2)
x1
- x co-ordinate of start of liney1
- y co-ordinate of start of linex2
- x co-ordinate of end of liney2
- y co-ordinate of end of linepublic void drawString(java.lang.String text, int x, int y)
text
- the String to be displayedx
- x co-ordinate for text placementy
- y co-ordinate for text placementpublic void erase()
public void erase(java.awt.Shape shape)
shape
- the shape object to be erasedpublic void eraseCircle(int xPos, int yPos, int diameter)
public void eraseOutline(java.awt.Shape shape)
shape
- the shape object to be erasedpublic void eraseRectangle(int xPos, int yPos, int width, int height)
public void eraseString(java.lang.String text, int x, int y)
text
- the String to be displayedx
- x co-ordinate for text placementy
- y co-ordinate for text placementpublic void fill(java.awt.Shape shape)
shape
- the shape object to be filledpublic void fillCircle(int xPos, int yPos, int diameter)
public void fillRectangle(int xPos, int yPos, int width, int height)
public java.awt.Color getBackgroundColor()
public java.awt.Font getFont()
public java.awt.Color getForegroundColor()
public java.awt.Dimension getSize()
public boolean isVisible()
public void setBackgroundColor(java.awt.Color newColor)
newColor
- the new color for the background of the Canvaspublic void setFont(java.awt.Font newFont)
newFont
- new font to be used for String outputpublic void setForegroundColor(java.awt.Color newColor)
newColor
- the new color for the foreground of the Canvaspublic void setSize(int width, int height)
width
- new widthheight
- new heightpublic void setVisible(boolean visible)
visible
- boolean value representing the desired visibility of
the canvas (true or false)public void wait(int milliseconds)
milliseconds
- the number