It's interesting to watch the actual workings of the framework approach (this example uses only init (), Start () and stop (), because paint () and destroy () are very simple and easy to grasp. The following patches will track the number of times these method calls and display them with paint ():
: Applet3.java
//Shows Init (), Start () and stop () activities
import java.awt.*;
Import java.applet.*;
public class Applet3 extends Applet {
String s;
int inits = 0;
int starts = 0;
int stops = 0;
public void init () {inits++;}
public void Start () {starts++;}
public void Stop () {stops++;}
public void Paint (Graphics g) {
s = "inits:" + inits +
", starts:" + starts +
", stops:" + stops;
g.DrawString (S, a);
}
///:~
Normally, when we overload a method, it is important to check whether we need to invoke the underlying class version of the method. For example, you might need to invoke super.init () when using init (). However, applet documentation specifically points out that Init (), Start (), and stop () are not useful in applets, so there is no need to invoke them here.
To experiment with this program, you'll find that if you minimize a Web browser, or overwrite it with another window, you can't call Stop () and start () (This behavior changes with different implementations; Consider comparing the behavior of the Web browser with the behavior of the program Viewer). The only occurrence of the invocation is when we move to a different Web page and then return the page that contains the program slice.