Applet in Java
- Applets are small Java applications that can be accessed on an Internet server, transported over Internet, and can be automatically installed and run as apart of a web document. Any applet in Java is a class that extends the java.applet.Applet class.
- An Applet class does not have any main() method.
- It is viewed using JVM. The JVM can use either a plug-in of the Web browser or a separate runtime environment to run an applet application.
- JVM creates an instance of the applet class and invokes init() method to initialize an Applet.
A Simple Applet
import java.awt.*; import java.applet.*; public class Simple extends Applet { public void paint(Graphics g) { g.drawString("A simple Applet", 20, 20); } }
Every Applet application must declare a
paint()
method. This method is defined by AWT class and must be overridden by the applet. paint()
method is called each time an applet neede to redisplay its output. Another important thing to notice about applet application is that, execution of an applet does not begin atmain()
method. In fact an applet application does not have any main() method.Advantages of Applets
- Very less response time as it works on the client side.
- Can be run using any browser, which has JVM running in it.
Applet class
Applet class provides all necessary support for applet execution, such as initializing and destroying of applet. It also provide methods that load and display images and methods that load and play audio clips.
No comments:
Post a Comment