Applet skeleton




                  1
Objectives

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




                                                  2
Recap
In the last class, you have studied about the life cycle of an
   applet
• Applet life cycle has different state
   –   Born
   –   Running
   –   Idle
   –   Dead
• The method useful for these state change
   –   init()
   –   start()
   –   stop()
   –   paint()
   –   destroy()



                                                             3
Applet Skeleton

• All but the most trivial applets override a set of
  methods that provides the basic mechanism
• Applet viewer interfaces to the applet and
  controls its execution
• Applet methods are, init( ), start( ), stop( ), and
  destroy( )
• All these methods already are defined by
  Applet



                                                        4
Applet Skeleton        contd…

• paint( ), is defined by the AWT Component
  class
• Applets do not need to override those methods
  they do not use
• However, only very simple applets will not need
  to define all of them
• These methods can be assembled into the
  skeleton shown in next slide


                                                    5
Applet Skeleton          contd…
import java.awt.*;
import java.applet.*;
/*
<applet code="AppletSkel"width=300height=100>
</applet>
*/
public class AppletSkel extends Applet {




                                                6
Applet Skeleton              contd…

// Called first
public void init() {
        // initialization
}
/* Called second, after init(). Also called whenever
the applet is restarted. */
public void start() {
        // start or resume execution
}



                                                       7
Applet Skeleton               contd..
// Called when the applet is stopped
public void stop(){
         // suspends execution
 }
/* Called when applet is terminated. This is the last
   method executed. */
public void destroy() {
   // perform shutdown activities
}




                                                        8
Applet Skeleton            contd..


// Called when an applet's window must be restored
   public void paint (Graphics g) {
        // redisplay contents of window
   }
}




                                                     9
Applet Skeleton       contd..


• When Applet runs, it generates the window
shown below




                                              10
Summary
  In this class, you have learnt
• All but the most trivial applets override a set of
  methods that provides the basic mechanism by which
  the browser or
• Applet methods are, init( ), start( ), stop( ), and
  destroy( )
• These methods can be assembled into the skeleton
  shown as shown in the code




                                                    11
Quiz

1. Which class defines paint() method
   a) Applet
   b) Component
   c) AWT
   d) None




                                        12
Frequently Asked Questions

1. Write applet skeleton code




                                  13

Applet skelton58

  • 1.
  • 2.
    Objectives On completion ofthis period, you would be able to learn • Applet Skeleton 2
  • 3.
    Recap In the lastclass, you have studied about the life cycle of an applet • Applet life cycle has different state – Born – Running – Idle – Dead • The method useful for these state change – init() – start() – stop() – paint() – destroy() 3
  • 4.
    Applet Skeleton • Allbut the most trivial applets override a set of methods that provides the basic mechanism • Applet viewer interfaces to the applet and controls its execution • Applet methods are, init( ), start( ), stop( ), and destroy( ) • All these methods already are defined by Applet 4
  • 5.
    Applet Skeleton contd… • paint( ), is defined by the AWT Component class • Applets do not need to override those methods they do not use • However, only very simple applets will not need to define all of them • These methods can be assembled into the skeleton shown in next slide 5
  • 6.
    Applet Skeleton contd… import java.awt.*; import java.applet.*; /* <applet code="AppletSkel"width=300height=100> </applet> */ public class AppletSkel extends Applet { 6
  • 7.
    Applet Skeleton contd… // Called first public void init() { // initialization } /* Called second, after init(). Also called whenever the applet is restarted. */ public void start() { // start or resume execution } 7
  • 8.
    Applet Skeleton contd.. // Called when the applet is stopped public void stop(){ // suspends execution } /* Called when applet is terminated. This is the last method executed. */ public void destroy() { // perform shutdown activities } 8
  • 9.
    Applet Skeleton contd.. // Called when an applet's window must be restored public void paint (Graphics g) { // redisplay contents of window } } 9
  • 10.
    Applet Skeleton contd.. • When Applet runs, it generates the window shown below 10
  • 11.
    Summary Inthis class, you have learnt • All but the most trivial applets override a set of methods that provides the basic mechanism by which the browser or • Applet methods are, init( ), start( ), stop( ), and destroy( ) • These methods can be assembled into the skeleton shown as shown in the code 11
  • 12.
    Quiz 1. Which classdefines paint() method a) Applet b) Component c) AWT d) None 12
  • 13.
    Frequently Asked Questions 1.Write applet skeleton code 13