Next: Lab Exercise 5: Paying
Up: In the Laboratory: CyberPetApplet
Previous: Lab Exercise 3: Paying
CyberPetApplet inherits a number of methods from its
superclasses. The main ones are
- start() is called once when the applet is started by the
browser or appletviewer. This method calls init() and paint()
automatically and then calls run() to get the applet running.
- run() is called by the start() method. It
starts the applet running.
- stop() is called by the browser or appletviewer when the
applet is quit.
- init() is called once when an applet starts up to
perform any required initializations.
- paint() paints the graphics on the applet. It is
called once when the applet starts and then it can be called by
repaint() whenever the applet's appearance is changed. This is where
you should place any drawing commands.
In addition to the above methods, which are inherited from
Applet, our applets implement the ActionListener interface, so
they also inherit the following method, which must be redefined in the
applet.
- actionPerformed() is called automatically whenever
one of the Buttons is clicked. It is passed information about
the ActionEvent. This is where you should place commands that
handle the applet's button clicks.
Of these methods, CyberPetApplet redefines init() and
implements actionPerformed(). Definitions for the other methods
don't appear in CyberPetApplet.
Place a System.out.println("In method X") statement, where
X is the name of the method, in each method of both the
CyberPetApplet and CyberPet classes. Run the program and note
the output that it produces. Write down the order of execution of the
statements in CyberPetApplet and CyberPet for various
actions, such as clicking on the eat button or the sleep button.
Next: Lab Exercise 5: Paying
Up: In the Laboratory: CyberPetApplet
Previous: Lab Exercise 3: Paying
Ralph Morelli {Faculty}
12/22/1999