Presentation is loading. Please wait.

Presentation is loading. Please wait.

Java Programming COMP-417 Applet

Similar presentations


Presentation on theme: "Java Programming COMP-417 Applet"— Presentation transcript:

1 Java Programming COMP-417 Applet
Chapter-1 Java Programming COMP-417 Applet

2 Applet: Java program that are typically embedded in xhtml documents
Applet: Java program that are typically embedded in xhtml documents. Also called web pages when a java -enabled web browsers loads a web page containing an applet, the applet downloads into the browses and executes. Applet Containers: the application in which the applet executes is known as the applet containers. It is the applet containers responsibility to load the applet class creates an instance of the applet and manages its life cycle. The JDK includes one called the "applet viewer" for testing applet as you develop them and before you embed them in web pages.

3 Applet Life-Cycle Methods
init() Begin Born start() stop() Running Idle start() paint() destroy() Dead End

4 Contd.. There are five applet method that are called by the applet container from the time the applet is loaded to the time it’s terminated by the browser. These methods correspond to various aspects of an applet’s life cycle. Which are inherited into your applet classes from class Applet or Japplet.

5 Contd.. The methods are listed below: 1.init() 2.start()
3.paint(Graphics) 4.stop() 5.destroy()

6 1. init (): called once by the applet containers when an applet is loaded for execution. This method initializes an applet. Typical action performed here are initializing fields, creating GUI components, loading sounds to play, loading images to display and creating threads. 2.start( ) : Called by the applet container after method init( ) completes execution. In addition, if the user browses to another website and later returns to the applet’s XHTML page, method ‘start’ is called again. This method perform any tasks that must be performed when the applet is loaded for the first time and that must be performed every time the applet’s XHTML page is revisited. Action performed have might include starting an animation or starting other threads of execution.

7 3.paint ( ) : Called by the applet container after methods init() and start(). Method paint() is also called when the applet needs to be repainted. If the user covers the applet with another open window on the screen and later uncovers it, the paint method is called. Typical action performed here involve is drawing with the Graphics object g that is passing to the paint method by the applet container. 4.stop( ) : This method is called by the applet container when the user leaves the applet's web page by browsing to another web page. Since it’s possible that the user might return to the web page containing the applet, method stop performs tasks that might be required to suspend the applet’s execution, so that the applet does not use computer processing time when it’s not displayed on the screen. Typical action performed here would stop the execution of animations and threads.

8 5.destroy( ) : This method is called by the applet container when the applet is being removed from memory. This occurs when the user exits the browsing session by closing all the browser windows and may also occurs at the browser’s discretion when the user has browsed to other web page. This method performs any tasks that are required to clean up resources allocated to the applet.

9 init() Begin Born start() Running Applet life cycle diagram paint()

10 init() Begin Born start() stop() Running Idle start() paint()
Applet life cycle diagram paint()

11 init() Begin Born start() stop() Running Idle start() paint()
Applet life cycle diagram paint() destroy() Dead End

12 init() Begin Born start() stop() Running Idle start() paint()
Applet life cycle diagram Prepared by Mohammed Ali Sohail paint() destroy() Dead End

13 program to demonstrate applet life cycle

14 import java.applet.Applet;
import java.awt.*; public class LifeCycle extends Applet { public void init() System.out.println(" init()"); } public void start() System.out.println(" start()"); public void paint(Graphics g) g.drawString("Welcome student",200,200); System.out.println(" paint()");

15 public void stop() { System.out.println(" stop()"); } public void destroy() System.out.println(" destroy()"); /* <HTML> <BODY> <APPLET CODE ="LifeCycle.class",WIDTH="800" HEIGHT="500"></APPLET> </BODY> </HTML>*/

16


Download ppt "Java Programming COMP-417 Applet"

Similar presentations


Ads by Google