Programming Language (JAVA)
Unit 6.11 – Applets
Presentation 1
Revision
1. Explain exception handling in Java.
2. List the types of exceptions in Java
language.
3. What are try, catch and throw blocks
used for?
Objectives
At the end of this presentation, you will be able to :
• Explain applet programming
• List the differences between applications and
applets
• Describe the different stages in the life cycle of
an applet
Java Programs
Java supports two kinds of programs.
• Java Applications are the normal standalone
programs.
• Java Applets are the programs that are to be
embedded in a Web page.
Applet Programming
• Applets are the Java programs that are
executed by the Web browser.
• Appletviewer is a Java utility to execute
applets.
• Applet is a special class file written to display
graphics in a Web browser.
Applets
• Applets are embedded in Web pages using
the HTML tag <APPLET>.
• When a Web page containing applet program
is run, it is downloaded to the memory
automatically and executed by the Web
browser.
• Applet gets displayed in the specific space
allocated in the Web page called Applet
Window.
Applets
Applets can contain embedded objects like :
• Animated graphics
• Video games
• Advanced text displays and images
• Audio
Applet Types
• Local Applets

Applets that are stored in the local machine
• Remote Applets

Applets that are stored in a remote computer.

These can be downloaded and embedded into Web
pages from the Internet.
Local Applets
Remote Applets
Applets Vs. Applications
Applets Applications
Applets are embedded in
Web pages and cannot be
run independently.
Applications can be
run independently.
Applet programs call certain
methods such as init(),
start(), stop(), and destroy()
of Applet class to start and
execute the applet code.
Programs use the
main() method for
initiating the
execution of the
code.
Applets Vs. Applications (Contd..)
Applets Applications
Applets cannot read from or
write to the files in the local
computer.
Applications can
read from or write
to local computer.
Applets enable the user to
interact graphically.
Applications do not
enable the user to
interact graphically.
Life Cycle of Applets
The four methods executed are :
1. init()
2. start()
3. stop()
4. destroy()
Life Cycle of Applets
init()
Initialisation State
• This method is executed when it is first
loaded into the memory.
• The applet is now said to exist in the
initialisation state.
init()
Syntax
public void init( )
{
<action statements>;
}
start()
Running State
• The start() method of the Applet Class is
executed whenever an applet is started or
restarted.
• The applet is now said to exist in the running
state.
start()
Syntax
public void start()
{
<action statements>;
}
stop()
Idle State
• The stop() method is executed when an applet is
closed.
• The applet is stopped automatically when the user
switches to another program or Web page.
• This can also be done by invoking explicitly the
stop() method of Applet class.
• When this is invoked the applet enters the idle
state.
stop()
Syntax
public void stop( )
{
<action statements>;
}
destroy()
Dead State
• The destroy() method is executed when a
Web page is closed.
• The applet is now said to be in the dead
state.
destroy()
Syntax
public void destroy( )
{
<action statements>;
}
paint()
• The paint() method of the Applet class is
executed automatically whenever the applet
is displayed in the Web page.
• This method is used to draw graphics in the
drawing area of the applet.
repaint()
• The repaint() method is used whenever you
want to redraw the applet’s drawing area.
• The repaint() method calls the update()
method.
• The update() method clears the applet area
and calls the paint() method.
paint()
Syntax
public void paint(Graphics g)
{
<display statements>;
}
Summary
In this presentation, you learnt the following
• Applets are Java programs mainly used in
Internet computing.
• The applet’s output is displayed within a subset
of the display area of the browser.
• Java applet inherits a set of default properties
from the Applet class.
• An applet enters the Initialisation state when it is
first loaded.
Summary
In this presentation, you learnt the following
• Applet enters the running state when the start()
method of Applet class is invoked.
• An applet becomes idle when it is stopped from
running.
• An applet is said to be dead when it is removed
from memory.
Assignment
1. Define an applet. List the uses of applets.
2. Sketch and explain the life cycle of an
applet.

Java programming Java programming Java programming

  • 1.
    Programming Language (JAVA) Unit6.11 – Applets Presentation 1
  • 2.
    Revision 1. Explain exceptionhandling in Java. 2. List the types of exceptions in Java language. 3. What are try, catch and throw blocks used for?
  • 3.
    Objectives At the endof this presentation, you will be able to : • Explain applet programming • List the differences between applications and applets • Describe the different stages in the life cycle of an applet
  • 4.
    Java Programs Java supportstwo kinds of programs. • Java Applications are the normal standalone programs. • Java Applets are the programs that are to be embedded in a Web page.
  • 5.
    Applet Programming • Appletsare the Java programs that are executed by the Web browser. • Appletviewer is a Java utility to execute applets. • Applet is a special class file written to display graphics in a Web browser.
  • 6.
    Applets • Applets areembedded in Web pages using the HTML tag <APPLET>. • When a Web page containing applet program is run, it is downloaded to the memory automatically and executed by the Web browser. • Applet gets displayed in the specific space allocated in the Web page called Applet Window.
  • 7.
    Applets Applets can containembedded objects like : • Animated graphics • Video games • Advanced text displays and images • Audio
  • 8.
    Applet Types • LocalApplets  Applets that are stored in the local machine • Remote Applets  Applets that are stored in a remote computer.  These can be downloaded and embedded into Web pages from the Internet.
  • 9.
  • 10.
  • 11.
    Applets Vs. Applications AppletsApplications Applets are embedded in Web pages and cannot be run independently. Applications can be run independently. Applet programs call certain methods such as init(), start(), stop(), and destroy() of Applet class to start and execute the applet code. Programs use the main() method for initiating the execution of the code.
  • 12.
    Applets Vs. Applications(Contd..) Applets Applications Applets cannot read from or write to the files in the local computer. Applications can read from or write to local computer. Applets enable the user to interact graphically. Applications do not enable the user to interact graphically.
  • 13.
    Life Cycle ofApplets The four methods executed are : 1. init() 2. start() 3. stop() 4. destroy()
  • 14.
  • 15.
    init() Initialisation State • Thismethod is executed when it is first loaded into the memory. • The applet is now said to exist in the initialisation state.
  • 16.
    init() Syntax public void init() { <action statements>; }
  • 17.
    start() Running State • Thestart() method of the Applet Class is executed whenever an applet is started or restarted. • The applet is now said to exist in the running state.
  • 18.
  • 19.
    stop() Idle State • Thestop() method is executed when an applet is closed. • The applet is stopped automatically when the user switches to another program or Web page. • This can also be done by invoking explicitly the stop() method of Applet class. • When this is invoked the applet enters the idle state.
  • 20.
    stop() Syntax public void stop() { <action statements>; }
  • 21.
    destroy() Dead State • Thedestroy() method is executed when a Web page is closed. • The applet is now said to be in the dead state.
  • 22.
    destroy() Syntax public void destroy() { <action statements>; }
  • 23.
    paint() • The paint()method of the Applet class is executed automatically whenever the applet is displayed in the Web page. • This method is used to draw graphics in the drawing area of the applet.
  • 24.
    repaint() • The repaint()method is used whenever you want to redraw the applet’s drawing area. • The repaint() method calls the update() method. • The update() method clears the applet area and calls the paint() method.
  • 25.
    paint() Syntax public void paint(Graphicsg) { <display statements>; }
  • 26.
    Summary In this presentation,you learnt the following • Applets are Java programs mainly used in Internet computing. • The applet’s output is displayed within a subset of the display area of the browser. • Java applet inherits a set of default properties from the Applet class. • An applet enters the Initialisation state when it is first loaded.
  • 27.
    Summary In this presentation,you learnt the following • Applet enters the running state when the start() method of Applet class is invoked. • An applet becomes idle when it is stopped from running. • An applet is said to be dead when it is removed from memory.
  • 28.
    Assignment 1. Define anapplet. List the uses of applets. 2. Sketch and explain the life cycle of an applet.