Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Applet in java

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 170
    Comment on it

    APPLET

    Applet are the client side web based program run on web browser. Applet implements the functionality of the clients.Dynamic and interactive programs runs inside a web page with a displayed Java capable browser.We don't have constructor in applet. Applet is invoked either through browser or through applet viewer utility provided by the JDK.

    APPLET LIFE CYCLE:

    There are four methods in the Applet class which gives you the framework on which you build any applet:

    1) init: This method is called once during the entire life cycle of an applet.This method is used for the initialization of your applet.

    2)start: After the browser calls the init method start method is automatically called . It is also called whenever the user get back to the page containing the applet after having gone off to other pages.This method basically called to start the applet.

    3)stop:With this method the browser moves off applet page.

    4)destroy: When the browser shuts down normally then this method is called . Because the applets is meant to live on an HTML page, you cannot normally leave resources behind after a user leaves the page that contains the applet.

    5)paint: This method is invoked immediately after the start() method, and also any time if the applet wants to repaint itself in the browser. It minimizes or refresh figures or images on the applet window.

    A HELLO WORLD APPLET:
    
    import java.applet.*;
    import java.awt.*;
    
    public class HWApplet extends Applet
    {
       public void paint (Graphics g)
       {
          g.drawString ("Hello World", 25, 50);
       }
    }
    
    

    These statements bring the classes into the scope of our applet class:

    • java.applet.Applet.
    • java.awt.Graphics.

    The Java compiler would not recognize the classes Applet and Graphics, which the applet class refers to without these import statements.

    THE APPLET CLASS: The java.applet.Applet class is an extension of every applet . These include methods that do the following:

    • To get the network location of the HTML file that contains the applet.
    • To get the network location of the applet class directory.
    • To print a status message in the browser.
    • To fetch an image.
    • To get applet parameters.
    • To fetch an audio clip.
    • To play an audio clip.
    • To resize the applet.
    • Also, the Applet class provides the user an interface by which the viewer or browser obtains information about the applet and controls the applets execution. The viewer may have the following options:
      • Initialization of an applet
      • Request information about the author, version and copyright of the applet.
      • Destruction of an applet
      • To start the applets execution
      • To stop the applets execution

      An Applet class provides the user with the default implementations of each of these methods. Those implementations can be overridden if necessary.

      The "Hello World" applet is complete as it stands. The only method overridden is the paint method.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: