Java Applet Basics

Source: Internet
Author: User

Java applets are small applications written in the Java language that are embedded directly into a page and interpreted by Java-enabled browsers (IE or Nescape) to perform programs that produce special effects. It can greatly improve the interactive ability and dynamic execution ability of Web pages. A Web page that contains applets is called a java-powered page, which can be called a Java-supported Web page.

When a user accesses such a Web page, the applet is downloaded to the user's computer for execution, but only if the user is using a Java-enabled web browser. Because the applet is executed on the user's computer, its execution speed is not limited by network bandwidth or modem access speed, and users can better appreciate the multimedia effects of the applets on the Web page.

The implementation of applet small application relies mainly on the applet class in the Java.applet package. Unlike a typical application, an applet application must be embedded in an HTML page to be interpreted and executed, and the applet can get parameters from the Web page and interact with the Web page.

The HTML file code for the Web page containing the applet must have a pair of tags such as <applet> and </applet>, and when the Java-enabled web browser encounters the tag, The corresponding applet code is downloaded and executed on the local computer.

An applet is a Java applet that is downloaded by a Java-enabled web browser by using the applet's HTML file. It can also be run through the appletviewer of Java development tools. An applet program cannot be separated from HTML files that use it. The information about applets in this HTML file should contain at least the following three points:

1 bytecode file name (compiled Java file with. class suffix)

2 byte code file address

3 Display the applet on the Web page.

An HTML file that adds an applet-related content just makes the page more vibrant, such as adding sound, animation, and other compelling features that don't change the applet-independent elements in the HTML file.

(i) Applet program development Steps

The main steps of applet program development are as follows:

1 Choose Edit or Windows Notepad tools as editor to build Java applet source program.

2 converts the source program of the applet to a bytecode file.

3 Compile the HTML file using class. Put the necessary <APPLET> statements inside the HTML file.

The following is a simple HelloWorld example to illustrate the development process of the applet program:

(1) Edit the Java source file for the applet

Create a folder C:\GHQ, set up Helloworld.java under this folder

The source code for the file is as follows:

import java.awt.*;
import java.applet.*;
public class HelloWorld extends Applet //继承Appelet类,这是Appelet Java程序的特点
{
  public void paint(Graphics g )
  {
   g.drawString("Hello World!",5,35);
  }
}

Save the above program in C:\ghq\HelloWorld.java file.

Related Article

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.