Java Applet Introduction
Recently I used WorldWind Java SDK for applet development. I read some information about the applet. To prevent forgetting, the record is as follows:
The applet is embedded into HTML through the <APPLET> tag. Therefore, the <APPLET> tag should contain at least the following information:
- Where to obtain the applet File
- Applet size
Applet and Java 2D
Program There are many related aspects. below is the applet inheritance Hierarchy Diagram
We can see that applet is a subclass of panel and can be used as a iner. The following is a typical applet tag in HTML: <APPLET code = "helloworld. class "width =" 800 "Height =" 600 "> </APPLET> the applet declaration period applet differs from the Panel in that the applet has lifecycle control. The Applet Class provides four methods for Lifecycle control. The following is a brief introduction to these four methods:
Call this method when initializing the applet. The applet can have a default constructor, but it is customary to perform all the initialization work in the init method rather than in the constructor.
This method will be executed after the browser calls the init method. This method is also executed when a user returns a page containing an applet from another page. It indicates that the start method can be executed multiple times. In contrast, the init method can only be executed once. The start method often restarts a thread for the applet, for example, restoring the animation. If the applet does not need to be suspended when the user leaves the current page, there is no need to implement this method (or stop method ).
This method is automatically called when the user leaves the page containing the applet.
This method is called only when the browser is normally closed. The following is an example of using the applet in the simplest form: <APPLET code = "helloworld. class "width =" 400 "Height =" 300 "> </APPLET> you can see that the Code attribute specifies the class file name and must contain. class extension; the width and height attributes determine the size of the applet window. Both are in pixels. The following attributes of the applet attribute used for encoding are used to locate the applet in a high-speed browser.
Code :
This attribute specifies the name of the Applet Class file. If codebase is specified, the path is relative to codebase. If codebase is not specified, the path is relative to the current page.
The path name must match the package name of the applet. For example, if the Applet Class is in the com. Demo package, the property should be code = "com. Demo. helloworld. Class" or "com/demo/helloworld. Class"
This optional attribute specifies the URL used to locate the class file. This URL can be a relative or a relative path. An example of a relative path is as follows:
Aproject/
| ----Page.html
| ---- Applets/
| ---- Helloworld. Class
You can write the <APPLET> tag in page.html as follows:
<APPLET code = "helloworld. Class" codebase = "applets" width = "800" Height = "600"> </APPLET>
This optional attribute lists Java archive files, including class files, and other resource files required by the applet. These files are obtained by the applet from the server before loading. This technology significantly accelerates the loading process because only one HTTP request is required to load jar files containing multiple small files. Jar files are separated by commas. For example:
<APPLET code = "helloworld. Class" ARCHIVE = "helllo. jar, demo/test. Jar" width = "800" Height = "600"> </APPLET>