What is Applet???
Applets are small applications that are accessed on an
Internet server, transported over the Internet, automatically
installed, and run as part of a Web document.
An Applet is a JAVA program that can be embedded into
HTMl page.
ADVANTAGES OF APPLET
CrossplatformandcanrunonWindows,MacOSandLinuxplatform.
Appletcanworkalltheversion ofJAVAplugin.
Applertsruninasandbox.
Appletsaresupportedbymostwebbrowsers.
Appletsareacachedinmostwebbrowsers.
DISADVANTAGES OF APPLET
JAVApluginis requiredtorunApplet.
JavaAppletrequires JVM.
IfAppletis notalready cachedinmachine,itwillbedownloadedfrominternetandwill
taketime.
Itis difficulttodesignandbuildgooduserinterfaceinAppletscomparedtoHTML
technology.
LIFECYCLEOF AN APPLET
• Applets life cycle includes the following methods :
• 1. Init( )
• 2. Start( )
• 3. Paint( )
• 4. Stop( )
• 5. Destroy( )
• init():Is usedtoinitializedtheapplet.Itis invokedonlyonce.
• start():Is invokedaftertheinit() methodor browser is maximized.It is usedtostart
theapplet.
• paint(graphicsg):is usedtopainttheapplet.Itprovidesgraphicsclassobjectthat
canbeusedfordrawingoval,rectangle,arcetc.
• stop():Is usedtostoptheapplet.Itis invokedwhenappletis stoporbrowseris
minimized.
• destroy(): Is usedtodestroytheapplet.Itis invokedonlyonce.
TYPESOF APPLETS
•Appletsaretwotypes:
1.Simpleapplets
• simpleappletscanbecreatedbyextendingappletclass
2.Japplets
• jappletscanbecreatedbyextendingjappletclassofjavax.Swing.Jappletpackage
CREATING APPLETS
● Appletsarecreatedbyextendingtheappletclass:
// SavefileasHelloWorld.java
importjava.applet.Applet;
importjava.awt.Graphics;
publicclass HelloWorldextendsApplet{
publicvoidpaint(Graphics g){
g.drawString("HelloWorld",20,20);}}
<appletcode="HelloWorld" width=200height=60>
</applet>