Java Reference
In-Depth Information
public void stop() {
}
public void destroy() {
}
}
As you can see from Listing 10-1, the applet model is deficient in comparison with
the Xlet model in two key ways: it cannot refuse a state transition, and it has no notion of
pausing or resuming execution. Note that at an applet does not need to override any of
the methods in Listing 10-1 if it has nothing to do during a state transition; the class pro-
vides default implementations of each.
Presenting the Applet's User Interface
Under the hood, applets are actually containers; specifically, they're subclasses of java.
awt.Container , meaning that applets can contain other user-interface objects or perform
their own painting by overriding the paint method. The Hello World applet shown in
Listing 10-2 demonstrates overriding the paint method, which the window toolkit
invokes when the applet is first drawn and whenever it is revealed.
Listing 10-2. Overriding the paint Method
package com.apress.rischpater.HelloApplet;
import java.applet.*;
import java.awt.Graphics;
public class HelloApplet extends Applet {
public void paint(Graphics g) {
g.drawString("Hello world!", 0, 0);
}
}
Listing 10-3 shows an approach that uses Java AWT components and containers.
 
Search WWH ::




Custom Search