Java Reference
In-Depth Information
Figure 14.19
imagedemo.jar file contains all the necessary files for the ImageDemo applet.
To demonstrate using JAR files and applets, the following example creates a
JAR file for the ImageDemo applet, adding the bytecode ImageDemo.class,
and the image file LogoD.jpg. Figure 14.19 shows the jar command that is used
to create the new JAR file named imagedemo.jar.
The following jardemo.html page demonstrates embedding the ImageDemo
applet using the archive attribute of the <applet> tag.
<html>
<body>
<h3>The ImageDemo applet</h3>
<applet code=”ImageDemo”
width=”300”
height=”200”
align=”center”
archive=”imagedemo.jar”>
<param name=”image” value=”LogoD.jpg”>
</applet>
</body>
</html>
When the <applet> tag is reached, the imagedemo.jar file is downloaded
and uncompressed by the JVM of the browser. The jardemo.html file creates
the same output as the one in Figure 14.16.
Lab 14.1: Writing an Applet
This lab will help you become familiar with writing applets.
1. Write a class named MyFirstApplet that extends Applet.
2. Within the paint() method, use the drawString() method of the
Graphics class to display your name in the applet.
3. Save and compile the MyFirstApplet class.
Search WWH ::




Custom Search