Introduction
 Applet is a special type of program that is embedded
in the webpage to generate the dynamic content.
 It runs inside the browser and works at client side.
 It can be executed by browsers running under many
platforms, including Windows , MacOS etc.
 Plug-in is required at client browser to execute applet.
 Applets don’t use the main method, but when they
are load, automatically call certain
methods(init,start,paint,stop,destroy).
 They are embedded inside a web page and executed
in brow
Life-Cycle
When an applet begins, the following
methods are called, in this sequence:
1. init( )
2. start( )
3. paint( )
When an applet is terminated, the
following sequence of method calls
takes place:
1. stop( )
2. destroy( )
Example
import java.applet.Applet;
import java.awt.Graphics;
// HelloWorld class extends
Applet public class HelloWorld extends Applet {
// Overriding paint() method
public void paint(Graphics g) {
g.drawString("Hello World", 20, 20);
}
}
java HelloWorld Error:
Main method not found in class HelloWorld, please define
the main method as: public static void main(String[] args)
ERROR:
Exp.Solution
There are two standard ways in which you can run an
applet :
1. Executing the applet within a Java-compatible we
browser.
2. Using an applet viewer, such as the standard tool,
appletviewer
<applet code="HelloWorld" width=200 height=60> </applet>
appletviewer RunHelloWorld.html
Adv./Disadv.
Advantage:-
• It is simple to make it work on Linux, Microsoft
Windows and OS X i.e. to make it cross platform.
• The same applet can work on “all” installed
versions of Java at the same time.
• It can move the work from the server to the client.
• Secured:-An un-trusted applet has no access to the
local machine and can only access the server it
came from.
• Java applets are fast.
Disadvantage:-
• It requires the Java plug-in.
• Some browsers, notably mobile browsers
running Apple iOS or Android do not run Java
applets at all.
• Some applets require a specific JRE.
Applet in JAVA

Applet in JAVA

  • 1.
    Introduction  Applet isa special type of program that is embedded in the webpage to generate the dynamic content.  It runs inside the browser and works at client side.  It can be executed by browsers running under many platforms, including Windows , MacOS etc.  Plug-in is required at client browser to execute applet.  Applets don’t use the main method, but when they are load, automatically call certain methods(init,start,paint,stop,destroy).  They are embedded inside a web page and executed in brow
  • 2.
    Life-Cycle When an appletbegins, the following methods are called, in this sequence: 1. init( ) 2. start( ) 3. paint( ) When an applet is terminated, the following sequence of method calls takes place: 1. stop( ) 2. destroy( )
  • 3.
    Example import java.applet.Applet; import java.awt.Graphics; //HelloWorld class extends Applet public class HelloWorld extends Applet { // Overriding paint() method public void paint(Graphics g) { g.drawString("Hello World", 20, 20); } } java HelloWorld Error: Main method not found in class HelloWorld, please define the main method as: public static void main(String[] args) ERROR:
  • 4.
    Exp.Solution There are twostandard ways in which you can run an applet : 1. Executing the applet within a Java-compatible we browser. 2. Using an applet viewer, such as the standard tool, appletviewer <applet code="HelloWorld" width=200 height=60> </applet> appletviewer RunHelloWorld.html
  • 5.
    Adv./Disadv. Advantage:- • It issimple to make it work on Linux, Microsoft Windows and OS X i.e. to make it cross platform. • The same applet can work on “all” installed versions of Java at the same time. • It can move the work from the server to the client. • Secured:-An un-trusted applet has no access to the local machine and can only access the server it came from. • Java applets are fast. Disadvantage:- • It requires the Java plug-in. • Some browsers, notably mobile browsers running Apple iOS or Android do not run Java applets at all. • Some applets require a specific JRE.