How To Create An Applet

Table of contents:

How To Create An Applet
How To Create An Applet

Video: How To Create An Applet

Video: How To Create An Applet
Video: Building your first Applet in Java - Tutorial for beginners | Introduction to Applets 2024, December
Anonim

An applet is a small program written in Java that is added to a web page and executed directly in the browser using a Java machine. Such applications are used to create interactive experiences on the site that cannot be created in HTML. The applet code works regardless of platform, so they can be launched by browsers of different operating systems.

How to create an applet
How to create an applet

Necessary

Java programming environment

Instructions

Step 1

Create a new project in your Java programming environment. The files required to run the applet have.java and.class extensions, but NetBeans has the ability to automatically generate an HTML file. It is desirable that all files be in the same directory.

Step 2

Create your first FirstProgram applet:

import java.awt. *

import applet.awt. *

public class FirstProgram extends Applet {

public void pain (Graphics dr) {

dr.drawString (“This is my first Java applet”, 20, 20); }}

Step 3

The import command is responsible for connecting ready-made classes that are in the special library Lib. In this case, java.awt and applet.awt are included, but the use of certain libraries depends entirely on the toolkit used in the program. Import java.awt includes the Graphics class, which is responsible for managing graphics and windowing operations. The applet.awt class imports data for working with applets.

Step 4

Next, a new class, FirstProgram, is created, which is extended using the extends parameter. The generated request will include all methods and data from the Applet, i.e. FirstProgram inherits all parameters.

Step 5

Public helps launch this applet from the browser. If you set the value to Private, then you cannot run the program from the outside.

Step 6

Compile the resulting program using the appropriate command in your programming environment. In NetBeans, go to the main class tab of your applet (FirstProgram.class) and right-click. Select the Run menu. After executing the program, the compiled html file will appear in the build folder of the project.

Step 7

With html, applets are included via a descriptor. In it you can set the parameters width, height. For example:

Recommended: