Java Applet Introduction

Source: Internet
Author: User
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:
    • Init
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.
    • Start
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 ).
    • Stop
This method is automatically called when the user leaves the page containing the applet.
    • Destory
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 :
    • 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"
    • Codebase
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>
    • Archive
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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.