Download presentation
Presentation is loading. Please wait.
Published bySherman Glenn Modified over 8 years ago
1
Applet: An applet is a java program that is transmitted over the network from the server to client & executed within clients browser. Applets are used to provides dynamic content & interactivity at client side.
2
hierarchy Java.lang.Object java.awt.Component java.awt.panel java.applet.Applet
3
Difference between java Application & java Applet 1) is a standalone program 1) is executed by the browser 2) executed using standalone JVM 2) browser provides JVM 3) entry point is the main() method 3)Several entry point called by browser like init() 4) can be graphical 4) almost graphical.
4
Applet client Applet Classes HTML Webserver 1.2 1.0 1.1 1.3 1.4 HTML contents Applet compone nt
5
1.0 send request for a page 1.1 HTML page with an embedded Applet is Returned. 1.2 shows the HTML contents & Applet component. 1.3 Applet object is created & life cycle method are invoked 1.4 content of Applets are displayed in the panel in browser.
6
An applet is a managed object & has life cycle methods. 1) A managed object is an object that is created & managed by run time environment. In case of Applet objects are created & managed by the browser. Each managed object has life cycle method that determines sequence of operations that can be performed by a managed object. Each Applet is represented by a class that extends Java.applet.Applet class. This class provides life cycle methods of an applet.
7
Init(): this method is invoked only once on an applet object just after its created this method is provided to executed initialization code. Syntax: public void init(); Start(): this method is invoke initially after init method & after that each time execution on Applet is resumed. This method denotes the starting point of execution of an Applet. stop(): this method is invoke when the execution of Applet is suspended. Public void stop(); Paint(): this method is used to draw the content of applet. It is invoke initially after start & after that each time repaint method is invoked.
8
Or contents of the Applet are redrawn. Public void paint(Graphics g); destroy():-it is invoked when Applet object is unloaded from the memory. public void destroy();
9
Client Browser r GraphicsApplet WebBro wser 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8
10
2.0 2.1 3.0 3.1 3.2 4.0 4.1
11
1.0 types the URL of a web page 1.1 send the request for the specified web page 1.2 web page within an applet is returned 1.3 Applet object is created 1.4 init(); 1.5 start(); 1.6 getGraphics(); 1.7 Graphics Object is returned & pass into paint(). 1.8 call paint method. 2.0 request other page 2.1 stop() 3.0 client request previous page 3.1 start(); 3.2 paint(); 4.0 client ends communication with the server 4.1 destroy();
12
For each GUI component in an interface a graphics object is created when the component is make visible. This graphics object can be used to drawing content on the component. Ex if we have the following interface NameText SubmitButton Label Frame/graphics Graphics
13
For this interface,graphics object shall be created when this interface make be visible. Graphics class provides following methods to draw component on a component. drawString():- is used to display a string on a component. Public void drawString(String text,int left,int top); String le ft top
14
drawLine(): is used to draw a line on a Component. Public void drawLine(int x1,int y1,int x2,int y2); drawRect():- public void drawRect (int left, int top, int width, int height); drawOval():- it is used to draw oval & circle. Note: use same signature for draw circle & pass the same coordinate for square. getGraphics():- method of component class is used to obtain the reference of graphics obj. for a component. Public graphics getGraphics(); Note: if getGraphics() method is invoke on a invisible component then null is returned.
15
An Applet has the following limitation :- 1) it does not have main method. 2) an applet can not access contact of local file system.(for security point of view). 3) An applet can only initiate socket communication with the host from where it was downloaded. Client Server Host A Applet For security reason
16
Note :1) Applet is the subclass of panel so give the color. Note 2)main purpose of applet of interactivity. Number Guessing Game To play the game,type a number between 0 to 100. Enter number here Guess
17
INTER APPLET COMMUNICATION : Inter applet communication is facilitate with the help of applet context. Applet context represent run time environment in which Applet are executed. Each time applet object is created run time environment store its reference into the applet object.
18
200 Ap[plet1 100 Applet2 100 300 200 100 300 Applet1 Applet2 RUN TIME ENVIROMENT Reference of applets that are currently executed in applet context. Applet context Reference of Applet context provided to each Applet object
19
getAppletContext():- method of applet class is used to obtain the reference of applet context in an applet. Public AppletContext getAppletContext(); appletcontext provides following methods:- GetApplet():- it is used to obtain the reference of an applet from the appletcontext. Public Applet getApplet(String name);
20
PASSING PARAMETER TO APPLET Parameters can be passed to an applet from the HTML page. subtag of applet is use to define a parameter for an applet in the HTML page. <param name=“parameter name” value =“parameter value”/>
21
getParameter():- it is a method,of applet class is used to read the value of a parameter in an applet. Public String getParameter(String parameter name); Following Sequence of event occurs: When an applet object is created by run time environment.
22
Applet Context RunTimeEnvironment Applet HTML PAGE 1.0 1.1 1.2 1.3 1.4
23
1.0 Read applet Tag & Identified Applet class 1.1 class is loaded & its instance is created 1.2 reference of appletcontext is stored 1.3 name & value of all parameters defined for applet are read. 1.4 all parameters(Name/ value) are stored in applet object. APPLet It is an object, getParameters method call on its & it provides all details with this reason given in figure.
24
LIFE CYCLE OF AN APPLET OBJECT CREATED INITILIZA TION RUNNING Destroyed NEWINTANSE(); INIT(); S T A R T () ; S T O P () ; Destroyed() Paint();
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.