Java Reference
In-Depth Information
Compiling the Applet
When you compile the applet, the compiler looks for the image file in the
same directory as the source code file. The image file, Smile.gif, is included in the
Chapter02 folder of the Data Disk that accompanies this topic. See the preface
for instructions on downloading the Data Disk, or see your instructor for a copy
of the graphic. The following steps assume that the Smile.gif file is located in the
Chapter02 folder on the Data Disk in drive A.
Perform the following steps to compile the applet.
To Compile the Applet
OTHER WAYS
1. With the Data Disk in drive A, click Tools on the menu bar. Click
Compile Java on the Tools menu.
2. If any error messages display in the Command Results window, click
WelcomeApplet.java in the Selector window, fix the errors, and then
repeat Step 1.
TextPad compiles the applet.
1. Press CTRL + 1
2. At command prompt,
type javac
WelcomeApplet.java
As when the Java application was compiled, possible errors that will be
generated while compiling the applet include an incorrect location for the Java
compiler, typing mistakes, omitting special characters, case-sensitive errors, and
file name errors. If you cannot determine and fix a coding error based on the
error messages and the information about errors on pages 74 through 77, con-
sult your instructor.
Creating an HTML Host Document
Because an applet is initiated and executed from within another language or run
as part of a Web page, you must identify a host , or reference program, to execute
the applet. The applet for this chapter is run as part of a Web page created in
HTML.
As you learned in Chapter 1, Hypertext Markup Language (HTML) is a set
of special codes called tags that specify how the text and other elements of a
Web page display. Unlike a programming language such as Java, HTML mainly is
used to display information; it is not suited to support user interaction to accept
input and generate output. A Java applet is thus ideal for adding that interactiv-
ity and functionality to a Web page.
An extensive understanding of HTML is not needed to build an HTML host
document for an applet. A few simple HTML tags to tell the browser where to
find and execute the applet file are all that are necessary to create a host for a
Java applet.
Coding an HTML Host Document
In HTML, a tag , or markup, is a code specifying how Web page content
should display or link to other documents. Each tag actually has two elements:
a start tag , which is enclosed in angle brackets < >, and an end tag , which uses
Search WWH ::




Custom Search