Sams Teach Yourself Java™ in 24 Hours (Covering Java 7 and Android)

(singke) #1
ptg7068951

238 HOUR 17:Creating Interactive Web Programs


If you are going to use a variable in other methods, it should not be created
inside an init()method because it only exists within the scope of that
method. Create any variables you need to use throughout a class as
instance variables.

Starting and Stopping an Applet
When the applet program starts running, the start()method is called.
When a program first begins, the init()method is followed by the
start()method. After that, the start()method only is called again if the
applet stops execution at some point and is later restarted.
The stop()method is called when an applet stops execution. This event
can occur when a userleaves the web page containing the applet and con-
tinues to another page. It also can occur when the stop()method is called
directly in a program.

Destroying an Applet
The destroy()method is the opposite of the init()method. It is handled
just before an applet completely closes down and completes running.

Putting an Applet on a Web Page
Appletsare placed on a web page by using HTML, the markup language
used to create web pages. HTMLis a way to combine formatted text,
images, sound, and other elements together and present them in a web
browser. HTMLuses markup commands called tags that aresurrounded
by <and >marks, including <img>for the display of images, <p>for the
insertion of a paragraph mark, and <h1>and</h1>to indicate the text that
they surround is a heading.
The performance of HTMLtags can be affected by attributes that deter-
mine how they function. The srcattribute of an imgtag provides the name
of the image file that should be displayed, as in this example of HTML
markup:
<img src=”graduation.jpg”>

This markup causes a web page to display the image stored in the file
graduation.jpg. One way to place applets on a web page is to useapplet
tag and several attributes. The following HTMLmarkup runs an applet on
a page:
Free download pdf