Java Reference
In-Depth Information
Lab 14.3: The Calculator Applet
The purpose of this lab is to demonstrate the similarities and differences
between applets and GUI applications. You will modify your Calculator
program from Chapter 13, “GUI Components and Event Handling,” so
that it can be used as an applet.
1. Copy all of the code from your solutions to Lab 13.1 in a new direc-
tory. You are going to modify your Calculator program, but I do not
want you to lose the work you did already. Make all of the follow-
ing changes to the copied version of your Calculator program.
2. Modify your Calculator class so that it extends JApplet instead of
JFrame.
3. Perform all the initialization and setup of your GUI and event han-
dling in the init() method. This might be as simple as renaming your
constructor to be the init() method, depending on how you wrote
your Calculator class.
4. Make any other necessary changes so that your Calculator class
compiles. (You might get some compiler errors because you
changed the parent class from JFrame to JApplet.)
5. Write a Web page that embeds your Calculator applet.
6. View your Web page, and test the Calculator to ensure that it works
properly.
Your Calculator applet should work similarly to your Calculator pro-
gram, except that now it can be viewed as an applet.
Lab 14.4: Applet Communication
The purpose of this lab is to demonstrate how two applets on the same
Web page can communicate with each other using the applet context. You
will write two applets: one that plays an audio clip, and a second applet
that controls which audio clip is played.
1.
Write a class named PlayClipApplet that extends Applet. Add a
field of type AudioClip called clip, and a field of type String called
clipName.
Search WWH ::




Custom Search