gpsys.lawnmower
Class LawnViewer

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Canvas
              |
              +--gpsys.lawnmower.LawnViewer

public class LawnViewer
extends java.awt.Canvas
implements LawnObserver

Provides a view of the lawn and lawnmower on the lawn.

Version:
$Revision: 1.1 $, $Date: 2000/07/05 16:26:49 $
Author:
Adil Qureshi
Department of Computer Science,
University College London,
Gower St,
London WC1E 6BT,
UK.
See Also:
Lawn, LawnObserver, Serialized Form

Inner classes inherited from class java.awt.Component
java.awt.Component.AWTTreeLock
 
Field Summary
(package private)  Lawn lawn
          The lawn being monitored.
(package private)  int mowerX
          The current X-coordinate of the lawnmower.
(package private)  int mowerY
          The current Y-coordinate of the lawnmower.
 
Fields inherited from class java.awt.Canvas
base, graphicsConfig, nameCounter, serialVersionUID
 
Fields inherited from class java.awt.Component
actionListenerK, adjustmentListenerK, appContext, assert, background, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, changeSupport, componentListener, componentListenerK, componentOrientation, componentSerializedDataVersion, containerListenerK, cursor, dropTarget, enabled, eventMask, focusListener, focusListenerK, font, foreground, hasFocus, height, incRate, inputMethodListener, inputMethodListenerK, isInc, isPacked, itemListenerK, keyListener, keyListenerK, LEFT_ALIGNMENT, locale, LOCK, minSize, mouseListener, mouseListenerK, mouseMotionListener, mouseMotionListenerK, name, nameExplicitlySet, newEventsOnly, ownedWindowK, parent, peer, peerFont, popups, prefSize, RIGHT_ALIGNMENT, serialVersionUID, textListenerK, TOP_ALIGNMENT, valid, visible, width, windowListenerK, x, y
 
Constructor Summary
LawnViewer(Lawn lawn)
          Create a new LawnViewer Object which provides a view of the specified Lawn.
 
Method Summary
 void init()
          Initialise the position of the mower on the lawn.
 void lawnCutting(int x, int y)
          Update the lawn view when a square on the lawn is being cut.
 void lawnGrown()
          Update the lawn view when the lawn regrows.
 void paint(java.awt.Graphics g)
          Override the Canvas paint() method so that the lawn and lawnmower is drawn on the Canvas.
 void update(java.awt.Graphics g)
          Override the Canvas update() method so that the Canvas is not cleared before it is redrawn.
 
Methods inherited from class java.awt.Canvas
, addNotify, constructComponentName, postsOldMouseEvents
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addPropertyChangeListener, addPropertyChangeListener, areInputMethodsEnabled, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, deliverEvent, disable, disableEvents, dispatchEvent, dispatchEventImpl, doLayout, enable, enable, enableEvents, enableInputMethods, eventEnabled, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentOrientation, getCursor, getDropTarget, getFont_NoClientCode, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getName, getNativeContainer, getParent_NoClientCode, getParent, getPeer, getPreferredSize, getSize, getSize, getToolkit, getToolkitImpl, getTreeLock, getWidth, getWindowForObject, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, initIDs, inside, invalidate, isDisplayable, isDoubleBuffered, isEnabled, isEnabledImpl, isFocusTraversable, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, layout, lightweightPrint, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, readObject, remove, removeComponentListener, removeFocusListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFont, setForeground, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus, validate, writeObject
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

lawn

Lawn lawn
The lawn being monitored.

mowerX

int mowerX
The current X-coordinate of the lawnmower.

mowerY

int mowerY
The current Y-coordinate of the lawnmower.
Constructor Detail

LawnViewer

public LawnViewer(Lawn lawn)
Create a new LawnViewer Object which provides a view of the specified Lawn.
Parameters:
lawn - The Lawn being viewed.
Method Detail

init

public void init()
Initialise the position of the mower on the lawn.

update

public void update(java.awt.Graphics g)
Override the Canvas update() method so that the Canvas is not cleared before it is redrawn.
Parameters:
g - The graphics Object associated with the Canvas.
Overrides:
update in class java.awt.Component

paint

public void paint(java.awt.Graphics g)
Override the Canvas paint() method so that the lawn and lawnmower is drawn on the Canvas.
Parameters:
g - The graphics Object associated with the Canvas.
Overrides:
paint in class java.awt.Canvas

lawnGrown

public void lawnGrown()
Update the lawn view when the lawn regrows.
Specified by:
lawnGrown in interface LawnObserver

lawnCutting

public void lawnCutting(int x,
                        int y)
Update the lawn view when a square on the lawn is being cut.
Specified by:
lawnCutting in interface LawnObserver
Parameters:
x - The X-coordinate of the square being cut.
y - The Y-coordinate of the square being cut.