Applets A Java application that is integrated into a webpage is called an ‘Applet’. A program embedded in the webpage to generate dynamic content. It runs inside the browser and functions as a front-end. It makes a page more interactive and dynamic by operating inside the web browser It is secured It can be executed by browsers running under many platforms, including Linux, Windows, Mac OS etc. Applets are hosted on web servers and inserted into html pages via applet tags.
Uses of Applets Can be used to provide interactive features to web applications. Can run automatically when the pages are viewed. Can play music, display documents, play animations etc. Makes a page more dynamic Can be used for multiple platforms. Reduce network load Get interactive user experience
Types of Applets Local Applet is written on our own, and then we will embed it into web pages. Local Applet is developed locally and stored in the local system. A web page doesn't need the get the information from the internet when it finds the local Applet in the system. It is specified or defined by the file name or pathname. There are two attributes used in defining an applet, i.e., the codebase that specifies the path name and code that defined the name of the file that contains Applet's code.
Types of Applets cntd … A remote applet is designed and developed by another developer. It is located or available on a remote computer that is connected to the internet. In order to run the applet stored in the remote computer, our system is connected to the internet then we can download run it. In order to locate and load a remote applet, we must know URL.
JApplet is a subclass of Applet, Applet class extends Panel, Panel class extends Container which is the subclass of Component
Include two import statements for awt (Abstract Window Toolkit) classes and an applet package that contains the class ‘Applet’ Declare the class named SimpleApplet as public paint() is defined by awt and is called at the beginning and at each time that the applet must redisplay its output Parameter Graphics describes the graphics environment in which the applet is running
For compiling: javac SimpleApplet.java Create an html file to embed. Eg : <html> <body> <applet code=“ SimpleApplet.class ” width=300 height=100></applet> </body> </html> c:\>javac GfgApplet.java c:\>appletviewer GfgApplet.java
java.awt.Component class The Component class provides method of applet. public void paint(Graphics g) is used to paint the Applet. It provides Graphics class object that can be used for drawing oval, rectangle, arc etc.