Applet initialization and termination




             http://improvejava.blogspot.in/   1
Objectives

On completion of this period, you would be able
  to learn
• Applet initialization
• Applet termination




                 http://improvejava.blogspot.in/   2
Recap

In the last class, you have studied about
• Applet Skeleton :
  which provide the basic structure for the applet
  programming




                 http://improvejava.blogspot.in/     3
Applet initialization and termination

• It is important to understand the order in which
  the various methods shown in the skeleton are
  called
• When an applet begins, the AWT calls the
  following methods in this sequence
           1. init( )
           2. start( )
           3. paint( )


                http://improvejava.blogspot.in/      4
Applet initialization and termination
                                                 contd..

• When an applet is terminated, the following
  sequence of method calls takes place
1. stop( )
2. destroy( )




               http://improvejava.blogspot.in/             5
Order of Applet Initialization
init( )
• The init( ) method is the first method to be
  called.
• It initializes variables
• It is called only once during the run time of your
  applet
start( )
• The start( ) method is called after init( )
• When a user leaves a web page and comes
  back, the applet resumes execution


                 http://improvejava.blogspot.in/   6
Order of Applet Initialization
paint( )
• Called each time the applet gets the focus
• The AWT monitors the windows system and
  notices things like other windows covering the
  applet
• Then calls paint() method to repair any damage
  the applet is uncovered or exposed




                http://improvejava.blogspot.in/   7
Order of Applet Termination Contd..
stop( )
• The stop( ) method is called when a web
  browser leaves the HTML document containing
  the applet
• When stop( ) is called, the applet is probably
  running
destroy( )
• If your applet needs to be removed completely
  from memory,
• The stop( ) method is always called before
  destroy( )

                 http://improvejava.blogspot.in/   8
Order of Applet Termination
                                                   contd..

When Applet runs , it generates the window below
as shown




                 http://improvejava.blogspot.in/             9
Summary
  In this class, you have learnt
• Methods called during applet initialization
     1. init( )
     2. start( )
     3. paint( )
• Methods called during applet termination
      1. stop( )
      2. destroy( )




                    http://improvejava.blogspot.in/   10
Frequently Asked Questions

• Write about the order of Applet initialization
• Write about the order of Applet termination




                 http://improvejava.blogspot.in/   11
Quiz

1. Is the sequence for applet is termination
    correct
   • stop( )
   • start()
   • destroy( )
   a) YES
   b) NO



               http://improvejava.blogspot.in/   12
Quiz                        Contd..

2.   Is the sequence for applet initialization correct
         • init( )
         • start( )
         • destroy()
      a) YES
      b) NO




                     http://improvejava.blogspot.in/             13

Applet init nd termination.59

  • 1.
    Applet initialization andtermination http://improvejava.blogspot.in/ 1
  • 2.
    Objectives On completion ofthis period, you would be able to learn • Applet initialization • Applet termination http://improvejava.blogspot.in/ 2
  • 3.
    Recap In the lastclass, you have studied about • Applet Skeleton : which provide the basic structure for the applet programming http://improvejava.blogspot.in/ 3
  • 4.
    Applet initialization andtermination • It is important to understand the order in which the various methods shown in the skeleton are called • When an applet begins, the AWT calls the following methods in this sequence 1. init( ) 2. start( ) 3. paint( ) http://improvejava.blogspot.in/ 4
  • 5.
    Applet initialization andtermination contd.. • When an applet is terminated, the following sequence of method calls takes place 1. stop( ) 2. destroy( ) http://improvejava.blogspot.in/ 5
  • 6.
    Order of AppletInitialization init( ) • The init( ) method is the first method to be called. • It initializes variables • It is called only once during the run time of your applet start( ) • The start( ) method is called after init( ) • When a user leaves a web page and comes back, the applet resumes execution http://improvejava.blogspot.in/ 6
  • 7.
    Order of AppletInitialization paint( ) • Called each time the applet gets the focus • The AWT monitors the windows system and notices things like other windows covering the applet • Then calls paint() method to repair any damage the applet is uncovered or exposed http://improvejava.blogspot.in/ 7
  • 8.
    Order of AppletTermination Contd.. stop( ) • The stop( ) method is called when a web browser leaves the HTML document containing the applet • When stop( ) is called, the applet is probably running destroy( ) • If your applet needs to be removed completely from memory, • The stop( ) method is always called before destroy( ) http://improvejava.blogspot.in/ 8
  • 9.
    Order of AppletTermination contd.. When Applet runs , it generates the window below as shown http://improvejava.blogspot.in/ 9
  • 10.
    Summary Inthis class, you have learnt • Methods called during applet initialization 1. init( ) 2. start( ) 3. paint( ) • Methods called during applet termination 1. stop( ) 2. destroy( ) http://improvejava.blogspot.in/ 10
  • 11.
    Frequently Asked Questions •Write about the order of Applet initialization • Write about the order of Applet termination http://improvejava.blogspot.in/ 11
  • 12.
    Quiz 1. Is thesequence for applet is termination correct • stop( ) • start() • destroy( ) a) YES b) NO http://improvejava.blogspot.in/ 12
  • 13.
    Quiz Contd.. 2. Is the sequence for applet initialization correct • init( ) • start( ) • destroy() a) YES b) NO http://improvejava.blogspot.in/ 13