APPLETS IN JAVA
A java applets are used to provide interactive features to web applications and can be executed by browsers for many platform.
Applets are small java programs that run inside a web browser. Java program embedded in HTML pages and can run automatically.
Applets are not allowed to read or write to our local disk. This restriction is necessary, as an applet may accidentally or wantonly destroy any data stored in the local machine.
Applets are used to provide dynamic and interactive content on a web page, such as animations, games, and other multimedia content.
Types of Applet:
=> Local Applet
=> Remote Applet
Syntax:
import java.awt.*;
import java.applet.*;
Life cycle of Applet:
Example:1
import java.awt.*;
import java.applet.Applet;
import java.graphics;
public class Linerect extends Applet
{
public void point(Graphics g)
{
g.drawline(5, 30, 300, 30);
g.drawRect(4, 40, 90, 55);
}
}
This applet runs in a web browser, you need to embed it in an HTML page:
<applet code="Linerect" width="150" height="50">
</applet>
</html>
Example:2
import java.applet.Applet;
import java.awt.Graphics;
public class HelloWorld extends Applet
{
public void paint(Graphics g)
{
g.drawString("Hello World", 20, 20);
}
}
This applet runs in a web browser, you need to embed it in an HTML page:
<html>
<body>
<applet code=”HelloWorld.class” width=”300” height=”300”>
</applet>
</body>
</html>