Java Reference
In-Depth Information
getParameter()
Looks up and returns the value of a named parameter, specified in the HTML
file that refers to the applet with the <PARAM> tag.
getCodeBase()
Returns the base URL from which the applet class file was loaded.
getDocumentBase()
Returns the base URL of the HTML file that refers to the applet.
showStatus()
Displays a message in the status line of the browser or applet viewer.
getAppletContext()
Returns the java.applet.AppletContext object for the applet. AppletContext
defines the useful showDocument() method that asks the browser to load and
display a new web page.
A First Applet
Example 15-1 shows what is probably the simplest possible applet you can write
in Java. Figure 15-1 shows the output it produces. This example introduces the
paint() method, which is invoked by the applet viewer (or web browser) when
the applet needs to be drawn. This method should perform graphical output—
such as drawing text or lines or displaying images—for your applet. The argument
to paint() is a java.awt.Graphics object that you use to do the drawing.
Figur e 15−1. A simple applet
Example 15−1: FirstApplet.java
package com.davidflanagan.examples.applet;
import java.applet.*;
// Don't forget this import statement!
import java.awt.*;
// Or this one for the graphics!
/** This applet just says "Hello World! */
public class FirstApplet extends Applet {
Search WWH ::




Custom Search