java.lang.Objectjava.awt.Component
java.awt.Container
java.awt.Panel
Canvas
The Canvas is the environment that the Turtles live in. It provides the view on the Turtle world. It also keeps a list of all living turtles, so that it can draw them all in the view and tell a turtle if it is alive. The Canvas has a scale factor that determines how much its view of the Turtle world is zoomed in or out. It may also choose to work with a Stepper to regulate how fast the turtles move. There is only ever one Canvas in existence. It can be retrieved with Canvas.getCanvas().
| Nested Class Summary |
| Nested classes inherited from class java.awt.Panel |
java.awt.Panel.AccessibleAWTPanel |
| Nested classes inherited from class java.awt.Container |
java.awt.Container.AccessibleAWTContainer |
| Nested classes inherited from class java.awt.Component |
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy |
| Field Summary |
| Fields inherited from class java.awt.Container |
|
| Fields inherited from class java.awt.Component |
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
| Fields inherited from interface java.awt.image.ImageObserver |
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
| Method Summary | |
void |
addTurtle(Turtle turtle)
Add a turtle to the master list of turtles, so that it will be drawn and will be considered alive. |
void |
clear()
Remove all turtles. |
void |
didStep()
A Turtle should call this whenever a step has been completed. |
void |
drawLine(double x1,
double y1,
double x2,
double y2,
java.awt.Color color)
Draw a line on teh canvas, given the start coordinates, end coordinates, and color. |
void |
drawTurtle(Turtle turtle,
double x,
double y,
double heading)
Draw the given turtle on this canvas, using its color and pen state. |
static Canvas |
getCanvas()
Only one canvas ever exists in the program. |
boolean |
isAlive(Turtle t)
Check whether this turtle is alive. |
void |
removeTurtle(Turtle turtle)
Remove a turtle from the master list of turtles. |
void |
setScale(double setting)
The applet should also call this to tell the turtles how to draw. |
void |
setStepper(Stepper stepper)
Attach this canvas to a stepper. |
void |
update(java.awt.Graphics g)
Draw all the living turtles in the given graphics context. |
| Methods inherited from class java.awt.Panel |
addNotify, getAccessibleContext |
| Methods inherited from class java.awt.Container |
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFont, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree |
| Methods inherited from class java.awt.Component |
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusUpCycle |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Method Detail |
public void addTurtle(Turtle turtle)
turtle - Turtle to add.public void clear()
public void didStep()
public void drawLine(double x1,
double y1,
double x2,
double y2,
java.awt.Color color)
x1 - x coordinate of start pointy1 - y coordinate of start pointx2 - x coordinate of end pointy2 - y coordinate of end pointcolor - Color to draw with
public void drawTurtle(Turtle turtle,
double x,
double y,
double heading)
turtle - Turtle to drawx - x coordinate of that turtley - y coordinate of that turtleheading - Heading of that turtlepublic static Canvas getCanvas()
public boolean isAlive(Turtle t)
t - Turtle to look for.
true or false.public void removeTurtle(Turtle turtle)
turtle - Turtle to remove.public void setScale(double setting)
setting - A number from 0 to 4 describing the scale. The default is 2.public void setStepper(Stepper stepper)
stepper - Stepper to attach.public void update(java.awt.Graphics g)