|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcsa120.shape.Canvas
Canvas is a class to allow for simple graphical drawing on a canvas.
Drawable objects can be added to and removed from the canvas.
The canvas is drawn only when the refresh() method is explicitly called.
Furthermore, if this canvas is created by a ControlledThread
the refresh() will incur a forced pause or delay based upon the settings
of the Controller
.
This code was originally based upon a general purpose Canvas, made for the
BlueJ "shapes" example, by Bruce Quig and Michael Kolling.
Constructor Summary | |
Canvas(String title,
int width,
int height)
Create a Canvas (with white background as default) |
|
Canvas(String title,
int width,
int height,
Color bgColor)
Create a Canvas. |
|
Canvas(String title,
int width,
int height,
String bgName)
Create a Canvas. |
Method Summary | |
void |
add(Drawable obj)
Add a drawable object to the canvas (however canvas is not automatically refreshed) |
void |
clear()
Clear all drawable objects from the canvas (however canvas is not automatically refreshed) |
void |
destroy()
Destroys the canvas, closing the associated window. |
Color |
getBackgroundColor()
Returns current background color |
int |
getHeight()
get the height of the canvas |
int |
getWidth()
get the width of the canvas |
void |
refresh()
Redraw all objects currently on the Canvas and then process desired pause if in a ControlledThread |
void |
remove(Drawable obj)
Remove a drawable object from the canvas (however canvas is not automatically refreshed) |
void |
setBackgroundColor(Color c)
Sets the current background color |
void |
setBackgroundColor(String cName)
Sets the current background color based upon a list of several known color names from java.awt.Color. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public Canvas(String title, int width, int height, Color bgColor)
title
- title to appear in Canvas Framewidth
- the desired width for the canvasheight
- the desired height for the canvasbgColor
- the desired background color of the canvaspublic Canvas(String title, int width, int height, String bgName)
title
- title to appear in Canvas Framewidth
- the desired width for the canvasheight
- the desired height for the canvasbgName
- the name of the desired background colorpublic Canvas(String title, int width, int height)
title
- title to appear in Canvas Framewidth
- the desired width for the canvasheight
- the desired height for the canvasMethod Detail |
public int getWidth()
public int getHeight()
public void remove(Drawable obj)
obj
- object to removepublic void destroy()
public void clear()
public void add(Drawable obj)
obj
- object to addpublic void refresh()
public Color getBackgroundColor()
public void setBackgroundColor(Color c)
c
- the new colorpublic void setBackgroundColor(String cName)
cName
- the name of the desired new color
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |