Java Reference
In-Depth Information
4.
import its.CounterGUI.CounterPanel;
5.
import java.awt.BorderLayout;
6.
7.
public class CounterApplet extends JApplet {
8.
9.
public void init(){
10.
CounterPanel cPane = new CounterPanel();
11.
this .getContentPane().add(cPane,BorderLayout.CENTER);
12.
}
13.
14.
public void start(){
15.
System.out.println("Start");
16.
}
17.
18.
public void stop(){
System.out.println("Stop");
19.
}
20.
21.
22.
public void destroy(){
System.out.println("Destroy");
23.
}
24.
25.
26.
27.
}
To make the applet run, it must be embedded in an HTML page. This is done by
inserting an applet tag ( <APPLET> ) into the page. In the tag one has to specify where
the applet's class files are found ( CODE ), its width ( WIDTH ) and height ( HEIGHT ). The
value of the CODE parameter is the path to the class files. If packages are used the
path has to reflect their structure. Also all classes used by the applet have to
!
be there in our example; this includes some classes from the its.CounterGUI
package. Here is the directory structure needed for the example:
its/Applet/CounterApplet. class
its/CounterGUI/CounterModel. class
its/CounterGUI/CounterPanel. class
its/CounterGUI/CounterListener. class
Our HTML page has the minimum structure; HTML-tags have many more for-
matting capabilities. The page looks like this:
<html>
<head>
<title>
Counter Applet
</title>
</head>
Search WWH ::




Custom Search