Java Reference
In-Depth Information
4. Write an HTML document named myfirst.html that embeds the
MyFirstApplet applet. Add a <h1> heading displaying “My First
Applet”, and any other HTML code you want.
5. Save the HTML document in the same directory as the bytecode file
MyFirstApplet.class.
6. Open the HTML document in appletviewer.
7.
Open the HTML document in a Web browser.
In appletviewer, you should see just the apple; in the Web browser, you
should see the applet plus any HTML code that appears in myfirst.html.
Lab 14.2: Using Applet Parameters
This lab will help you become familiar with using applet parameters.
This lab makes some modifications to the MyFirstApplet class from
Lab 14.1.
1. Add the init() method to your MyFirstApplet class, and also a field
of type String called name.
2. Within the init() method, initialize the name field to be the value of a
parameter called username. If no username parameter is defined,
have the name field default to be your name.
3. Modify the paint() method so that it displays the name field instead
of your name.
4. Save and compile the MyFirstApplet class.
5. View the myfirst.html page in a browser or appletviewer. You
should see your name because you have not defined a username
applet parameter yet.
6. Modify your myfirst.html file so that it defines a username parame-
ter. Assign the value of this parameter to be something other than
your name.
7.
View the myfirst.html page again in a browser or appletviewer.
The output is similar to that of Lab 14.1, except that the name dis-
played should be the value of the username parameter defined in
myfirst.html.
Search WWH ::




Custom Search