1 / 24

Applet:

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. hierarchy. Java.lang.Object java.awt.Component java.awt.panel

lavonn
Télécharger la présentation

Applet:

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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. 1.0 Webserver client HTML 1.3 1.1 Applet Applet Classes 1.2 1.4 HTML contents Applet component

  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 Browserr Graphics Applet WebBrowser 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 Graphics Graphics Name Text Frame/graphics Submit Button Label

  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,intleft,int top); top String left

  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 Applet Applet For security reason Host A

  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. Reference of Applet context provided to each Applet object RUN TIME ENVIROMENT Applet context Applet1 Applet2 200 300 100 Applet2 Ap[plet1 100 100 300 200 Reference of applets that are currently executed in applet context.

  19. getAppletContext():- method of applet class is used to obtain the reference of applet context in an applet . • Public AppletContextgetAppletContext(); • 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 . • <param> subtag of applet is use to define a parameter for an applet in the HTML page . • <applet > • <param name=“parameter name” • value =“parameter value”/> • </applet>

  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. HTML PAGE Applet Applet Context RunTimeEnvironment 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. It is an object, getParameters method call on its & it provides all details with this reason given in figure. APPLet

  24. LIFE CYCLE OF AN APPLET OBJECT CREATED INITILIZATION NEWINTANSE(); INIT(); START(); STOP(); Destroyed() Destroyed RUNNING Paint();

More Related