1 / 12

Applet Architecture And Applet Class

Applet Architecture And Applet Class. Presented by: Judy A Pasi Ibansara Warlapih Jesson D Thangkhiew. What is an Applet ? . Applets are Java programs that may be embedded into HTML documents. The applet runs in the page as soon as it has been downloaded.

isaura
Download Presentation

Applet Architecture And Applet Class

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 Architecture AndApplet Class Presented by: Judy A Pasi IbansaraWarlapih Jesson D Thangkhiew

  2. What is an Applet ? • Applets are Java programs that may be embedded into HTML documents. The applet runs in the page as soon as it has been downloaded. • More specifically Java applets are Java programs that inherit the Applet (AWT) or JApplet class (Swing).

  3. 1 . Request for Mypage.html . MyApplet.class 3 executeshere 2 . Sends Mypage.html and MyApplet.class Applet Architecture Applet Program MyApplet.class Webpage with applet Mypage.html Client Web Server

  4. Creating an Applet • To create an Applet, a subclass of the Applet class (AWT) or JApplet class(Swing) should be created. • Example, public class MyApplet extends JApplet { ……… }

  5. Methods of the Applet Class • init Method • Similar to a constructor • Called when applet is first loaded into the browser. • Not called every time the applet is executed.(except in certain browser versions) • start Method • The start method starts the execution of the applet – Called immediately after init. • Reinvoked each time the user returns to the page with the applet. • Used to start animation threads • paint Method • Called by the browser after init and start, and again whenever the browser redraws the screen, (typically when part of the screen has been obscured and then re exposed) • This method is where user-level drawing is placed

  6. Methods of the Applet Class (contd.) • stop Method • Most applets that override the start should also override the stop method. • Called when browser leaves the page • Used to stop animation threads • The stop method suspends the applet's execution. • destroy Method Invoked when browser exits normally • used for applets that need to release additional resources.

  7. Begin init() Born ( Load applet ) stop() start() Stopped Idle Running Display destroy() paint() start() End Dead Destroyed Life Cycle of An Applet

  8. public void init() • { • // called when applet is first created • } • public void start() • { • // called when applet is started and then restarted • } • public void paint(Graphics G) • { • // invoked when screen needs to be drawn or redrawn • }

  9. public void paint(Graphics G) • { • // invoked when screen needs to be drawn or redrawn • } • public void stop() • { • //called when the user leaves the page containing the applet

  10. public void destroy() • { • // called when applet is permanently destroyed • }

  11. A “Hello World” Applet import java.awt.*; import javax.swing.*; public class HelloApplet extends JApplet { public void paint(Graphics g) { super.paint(g); g.drawString(“Hello World”, 25, 25); // draw string at x=25 and y=25 } }

  12. Adding Applets to an HTML Document <applet code=“MyApplet.class” height=“200” width=“100”> </applet>

More Related