1 applets are small applications that are accessed on an internet server, transported over the...

9
1 • Applets are small applications that are accessed on an Internet server, transported over the internet, automatically installed and run as a part of web document. • Applets interact with the user through the AWT, not through the console based I/O classes. Applets

Upload: alexia-turner

Post on 29-Jan-2016

213 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 1 Applets are small applications that are accessed on an Internet server, transported over the internet, automatically installed and run as a part of web

1

• Applets are small applications that are accessed

on an Internet server, transported over the

internet, automatically installed and run as a

part of web document.

• Applets interact with the user through the AWT,

not through the console based I/O classes.

Applets

Page 2: 1 Applets are small applications that are accessed on an Internet server, transported over the internet, automatically installed and run as a part of web

2

• Every applet that you create must be a

subclass of Applet, in the java.applet package.

• Applets don’t have a main().

• An applet begins execution when the name of

its class is passed to an applet viewer or the

web browser.

Applets

Page 3: 1 Applets are small applications that are accessed on an Internet server, transported over the internet, automatically installed and run as a part of web

3

To execute an Applet

• Edit Java source file.

• Compile your program.

• Make an HTML file that contains the tag that

loads the applet.

• Execute the applet viewer, specifying the name

of your applet’s source file.

Page 4: 1 Applets are small applications that are accessed on an Internet server, transported over the internet, automatically installed and run as a part of web

4

Applet Architecture

• All applets are subclasses of Applet.

• An applet is a window-based program.

• Applets are event driven.

• The user initiates interaction with the applet.

Page 5: 1 Applets are small applications that are accessed on an Internet server, transported over the internet, automatically installed and run as a part of web

5

Applet class

• Applets override a set of methods that provide the basic

mechanism by which the browser interfaces to the applet

and controls its execution.

• init(), start(), stop() and destroy() – apply to applets and

are defined by Applet.

• Applets override the paint() of the AWT Component class.

This is called when the applet’s output is redisplayed.

Page 6: 1 Applets are small applications that are accessed on an Internet server, transported over the internet, automatically installed and run as a part of web

6

Life Cycle of an Applet• When an applet begins:-– init() – first method – initializes variables – called

only once.– start() – called after init()- used to restart an

applet – called when an applet’s HTML document is displayed onscreen.

– paint() – called when applet’s output must be redrawn. paint() has one parameter of type Graphics – this will contain the graphics context, which describes the graphics envt in which the applet is executing.

Page 7: 1 Applets are small applications that are accessed on an Internet server, transported over the internet, automatically installed and run as a part of web

7

Life Cycle of an Applet• When an applet terminates:-

– stop() – called when a web browser leaves the

HTML document containing the applet – when it

goes to another page.

– destroy() – called when the envt determines that

your applet needs to be removed completely

from the memory.

Page 8: 1 Applets are small applications that are accessed on an Internet server, transported over the internet, automatically installed and run as a part of web

8

Life Cycle of an Applet

Page 9: 1 Applets are small applications that are accessed on an Internet server, transported over the internet, automatically installed and run as a part of web

9

Applet tag

• Applet tag is used to start an applet from an HTML

document and from an applet viewer.

<Applet code=appletfile Width=w Height=h>

</Applet>

• Code – gives the name of the file containing applet’s

compiled .class file.

• Width & Height size of the applet in pixels.