interactive java note - m06_un11_p01

Upload: ebby-kyle

Post on 06-Apr-2018

217 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/3/2019 Interactive Java Note - M06_UN11_P01

    1/28

    Programming Language (JAVA)

    Unit 6.11 Applets

    Presentation1

  • 8/3/2019 Interactive Java Note - M06_UN11_P01

    2/28

    Revision

    1. Explain exception handling in Java.

    2. List the types of exceptions in Java

    language.

    3. What are try, catch and throw blocksused for?

  • 8/3/2019 Interactive Java Note - M06_UN11_P01

    3/28

    Objectives

    At the end of this presentation, you will be able to :

    Explain applet programming

    List the differences between applications andapplets

    Describe the different stages in the life cycle ofan applet

  • 8/3/2019 Interactive Java Note - M06_UN11_P01

    4/28

    Java Programs

    Java supports two kinds of programs.

    Java Applications are the normal standalone

    programs.

    Java Applets are the programs that are to beembedded in a Web page.

  • 8/3/2019 Interactive Java Note - M06_UN11_P01

    5/28

    Applet Programming

    Appletsare the Java programs that areexecuted by the Web browser.

    Appletviewer is a Java utility to executeapplets.

    Applet is a special class file written to display

    graphics in a Web browser.

  • 8/3/2019 Interactive Java Note - M06_UN11_P01

    6/28

    Applets

    Applets are embedded in Web pages usingthe HTML tag .

    When a Web page containing applet programis run, it is downloaded to the memoryautomatically and executed by the Webbrowser.

    Applet gets displayed in the specific spaceallocated in the Web page called AppletWindow.

  • 8/3/2019 Interactive Java Note - M06_UN11_P01

    7/28

    Applets

    Applets can contain embedded objects like :

    Animated graphics

    Video games

    Advanced text displays and images

    Audio

  • 8/3/2019 Interactive Java Note - M06_UN11_P01

    8/28

    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.

  • 8/3/2019 Interactive Java Note - M06_UN11_P01

    9/28

    Local Applets

  • 8/3/2019 Interactive Java Note - M06_UN11_P01

    10/28

    Remote Applets

  • 8/3/2019 Interactive Java Note - M06_UN11_P01

    11/28

    Applets Vs. Applications

    Applets Applications

    Applets are embedded in

    Web pages and cannot be runindependently.

    Applications can be

    run independently.

    Applet programs call certain

    methods such as init(),

    start(),stop(), and destroy()of Applet class to start andexecute the applet code.

    Programs use the

    main() method for

    initiating theexecution of thecode.

  • 8/3/2019 Interactive Java Note - M06_UN11_P01

    12/28

    Applets Vs. Applications (Contd..)

    Applets Applications

    Applets cannot read from or

    write to the files in the localcomputer.

    Applications can

    read from or writeto local computer.

    Applets enable the user tointeract graphically.

    Applications do notenable the user to

    interact graphically.

  • 8/3/2019 Interactive Java Note - M06_UN11_P01

    13/28

    Life Cycle of Applets

    The four methods executed are :

    1. init()

    2. start()

    3. stop()

    4. destroy()

  • 8/3/2019 Interactive Java Note - M06_UN11_P01

    14/28

    Life Cycle of Applets

  • 8/3/2019 Interactive Java Note - M06_UN11_P01

    15/28

    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.

  • 8/3/2019 Interactive Java Note - M06_UN11_P01

    16/28

    init()

    Syntax

    public void init( )

    {

    ;

    }

  • 8/3/2019 Interactive Java Note - M06_UN11_P01

    17/28

    start()

    Running State

    The start()method of the Applet Class isexecuted whenever an applet is started orrestarted.

    The applet is now said to exist in the running

    state.

  • 8/3/2019 Interactive Java Note - M06_UN11_P01

    18/28

    start()

    Syntax

    public void start()

    {

    ;

    }

  • 8/3/2019 Interactive Java Note - M06_UN11_P01

    19/28

    stop()

    Idle State

    The stop() method is executed when anapplet is closed.

    The applet is stopped automatically when theuser switches to another program or Webpage.

    This can also be done by invoking explicitlythe stop() method of Applet class.

    When this is invoked the applet enters the

    idle state.

  • 8/3/2019 Interactive Java Note - M06_UN11_P01

    20/28

    stop()

    Syntax

    public void stop( )

    {

    ;

    }

  • 8/3/2019 Interactive Java Note - M06_UN11_P01

    21/28

    destroy()

    Dead State

    The destroy() method is executed when a

    Web page is closed.

    The applet is now said to be in the deadstate.

  • 8/3/2019 Interactive Java Note - M06_UN11_P01

    22/28

    destroy()

    Syntax

    public void destroy( )

    {

    ;

    }

  • 8/3/2019 Interactive Java Note - M06_UN11_P01

    23/28

    paint()

    Thepaint()method of the Applet class isexecuted automatically whenever the applet

    is displayed in the Web page. This method is used to draw graphics in the

    drawing area of the applet.

  • 8/3/2019 Interactive Java Note - M06_UN11_P01

    24/28

    repaint()

    The repaint() method is used whenever youwant to redraw the applets drawing area.

    The repaint() method calls the update()method.

    The update() method clears the applet area

    and calls thepaint() method.

  • 8/3/2019 Interactive Java Note - M06_UN11_P01

    25/28

    paint()

    Syntax

    public void paint(Graphics g)

    {

    ;

    }

  • 8/3/2019 Interactive Java Note - M06_UN11_P01

    26/28

    Summary

    In this presentation, you learnt the following

    Applets are Java programs mainly used in

    Internet computing.

    The applets output is displayed within asubset of the display area of the browser.

    Java applet inherits a set of defaultproperties from the Applet class.

    An applet enters the Initialisation state when

    it is first loaded.

  • 8/3/2019 Interactive Java Note - M06_UN11_P01

    27/28

    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 fromrunning.

    An applet is said to be dead when it is removedfrom memory.

  • 8/3/2019 Interactive Java Note - M06_UN11_P01

    28/28

    Assignment

    1. Define an applet. List the uses of applets.

    2. Sketch and explain the life cycle of anapplet.