Summary of classes
We have now seen three different kinds of classes:
- Classes that extend WindowController. They
require a begin() method to do initialization and may
contain methods (such as onMouseClick(Location point)) to
respond to mouse events.
- Classes that don't extend anything. They require a class
constructor (with the same name as the class) to do
initialization. They may contain any methods necessary.
Examples include Tshirt, Magnet, etc.
- Classes that extend ActiveObject. They also
require a constructor to do initialization. The last statement of
the constructor calls method start(), though you do NOT
provide a start method yourself. Instead you must
provide a run() method which will eventually be
called by start(). Any while loop in
execute() must generally include a pause(double)
call, both to provide better animation and to allow the processor
to handle other processes that desire to run.
Always remember, to create an ActiveObject you:
- define a class that "extends ActiveObject"
- define its constructor and say "start()" at the end.
- define at least a "public void run()" method.
- include a pause statement in animation loops in run().
We quickly reviewed the Tree example from last lecture.
See also the dripping paint example:
Demo. Dripper.