All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class gpsys.lawnmower.LawnViewer

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

public class LawnViewer
extends Canvas
implements LawnObserver
Provides a view of the lawn and lawnmower on the lawn.

Author:
Adil Qureshi
Department of Computer Science,
University College London,
Gower St,
London WC1E 6BT,
UK.
See Also:
Lawn, LawnObserver

Variable Index

 o lawn
The lawn being monitored.
 o mowerX
The current X-coordinate of the lawnmower.
 o mowerY
The current Y-coordinate of the lawnmower.

Constructor Index

 o LawnViewer(Lawn)
Create a new LawnViewer Object which provides a view of the specified Lawn.

Method Index

 o init()
Initialise the position of the mower on the lawn.
 o lawnCutting(int, int)
Update the lawn view when a square on the lawn is being cut.
 o lawnGrown()
Update the lawn view when the lawn regrows.
 o paint(Graphics)
Override the Canvas paint() method so that the lawn and lawnmower is drawn on the Canvas.
 o update(Graphics)
Override the Canvas update() method so that the Canvas is not cleared before it is redrawn.

Variables

 o lawn
 Lawn lawn
The lawn being monitored.

 o mowerX
 int mowerX
The current X-coordinate of the lawnmower.

 o mowerY
 int mowerY
The current Y-coordinate of the lawnmower.

Constructors

 o LawnViewer
 public LawnViewer(Lawn lawn)
Create a new LawnViewer Object which provides a view of the specified Lawn.

Parameters:
lawn - The Lawn being viewed.

Methods

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

 o update
 public void update(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 Component
 o paint
 public void paint(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 Canvas
 o lawnGrown
 public void lawnGrown()
Update the lawn view when the lawn regrows.

 o lawnCutting
 public void lawnCutting(int x,
                         int y)
Update the lawn view when a square on the lawn is being cut.

Parameters:
x - The X-coordinate of the square being cut.
y - The Y-coordinate of the square being cut.

All Packages  Class Hierarchy  This Package  Previous  Next  Index