SlideShare a Scribd company logo
GUI IN JAVA

    What is an Applet?

Introduction

Applet is java program that can be embedded into HTML pages. Java applets run on the java
enables web browsers such as Mozilla and internet explorer. Applet is designed to run
remotely on the client browser, so there are some restrictions on it. Applet can't access
system resources on the local computer. Applets are used to make the web site more
dynamic and entertaining.

Advantages of Applet:

       Applets are cross platform and can run on Windows, Mac OS and Linux platform
       Applets can work all the version of Java Plug-in
       Applets are supported by most web browsers
       Applets are cached in most web browsers, so will be quick to load when returning to
       a web page
       User can also have full access to the machine if user allows

Disadvantages of Java Applet:

       Java plug-in is required to run applet
       Java applet requires JVM so first time it takes significant start-up time
       If applet is not already cached in the machine, it will be downloaded from internet
       and will take time
       It’s difficult to design and build good user interface in applets compared to HTML
       technology

Applet versus Application

       Applets as previously described, are the small programs while applications are larger
       programs.
       Applets don't have the main method while in an application execution starts with
       the main method.
       Applets can run in our browser's window or in an appletviewer. To run the applet in
       an appletviewer will be an advantage for debugging.
       Applets are designed for the client site programming purpose while the applications
       don't have such type of criteria.

       Applet is the powerful tools because it covers half of the java language picture. Java
       applets are the best way of creating the programs in java. There are a less number of
       java programmers that have the hands on experience on java applications.
       Applications are also the platform independent as well as byte oriented just like the
       applets.
Applets are designed just for handling the client site problems. While the java
           applications are designed to work with the client as well as server.
           Applications are designed to exist in a secure area. While the applets are typically
           used.

Applications and applets have much of the similarity such as both have most of the same
features and share the same resources. Applets are created by extending the
java.applet.Applet class while the java applications start execution from the main method.
Applications are not too small to embed into a html page so that the user can view the
application in your browser. On the other hand applet has the accessibility criteria of the
resources. The key feature is that while they have so many differences but both can perform
the same purpose.

     The Life cycle of an Applet


Introduction

In this Section you will learn about the lifecycle of an applet and different methods of an
applet. Applet runs in the browser and its lifecycle method are called by JVM when it is
loaded and destroyed. Here are the lifecycle methods of an Applet:




init( )

The init( ) method is the first method to be called. This is where you should initialize
variables. This method is called only once during the run time of your applet.

start( )
The start( ) method is called after init( ). It is also called to restart an applet after it has been
stopped. Whereas init( ) is called once—the first time an applet is loaded—start( ) is called
each time an applet’s HTML document is displayed onscreen. So, if a user leaves a web page
and comes back, the applet resumes execution at start( ).

paint( )

The paint( ) method is called each time your applet’s output must be redrawn. This situation
can occur for several reasons. For example, the window in which the applet is running may
be overwritten by another window and then uncovered. Or the applet window may be
minimized and then restored. paint( ) is also called when the applet begins execution.
Whatever the cause, whenever the applet must redraw its output, paint( ) is called. The
paint( ) method has one parameter of type Graphics. This parameter will contain the
graphics context, which describes the graphics environment in which the applet is running.
This context is used whenever output to the applet is required.

stop( )

The stop( ) method is called when a web browser leaves the HTML document containing the
applet—when it goes to another page, for example. When stop( ) is called, the applet is
probably running. You should use stop( ) to suspend threads that don’t need to run when
the applet is not visible. You can restart them when start( ) is called if the user returns to the
page.

destroy( )

The destroy( ) method is called when the environment determines that your applet needs
to be removed completely from memory. At this point, you should free up any resources the
applet may be using. The stop( ) method is always called before destroy( ).

More Related Content

PDF
Java applets and working principles
PPT
Applet execution
ODP
Applets
PPS
PDF
Java applet-basics
DOCX
Java applet-basics
PPTX
Java Applets
PPT
Appl clas nd architect.56
Java applets and working principles
Applet execution
Applets
Java applet-basics
Java applet-basics
Java Applets
Appl clas nd architect.56

What's hot (20)

PPTX
Applet programming in java
PPT
Basics of applets.53
PPT
PDF
Java applet basics
PPT
Java applet
PPTX
Appletjava
PDF
ITFT- Applet in java
PPTX
applet using java
PPTX
L18 applets
PPT
Java applets
PPT
Java Applet
PPT
Java applets
PDF
27 applet programming
PPT
Applet init nd termination.59
PPTX
Applet progming
PPTX
Applet (1)
PPTX
6.applet programming in java
PDF
JAVA APPLETS
PPTX
Applet programming
Applet programming in java
Basics of applets.53
Java applet basics
Java applet
Appletjava
ITFT- Applet in java
applet using java
L18 applets
Java applets
Java Applet
Java applets
27 applet programming
Applet init nd termination.59
Applet progming
Applet (1)
6.applet programming in java
JAVA APPLETS
Applet programming
Ad

Viewers also liked (10)

DOCX
Lecture7 oopj
PDF
Sistema Génesis y Portales Institucionales
DOCX
Lecture6 oopj
DOCX
Lecture3 oopj
PPTX
02 Hidup ini Pilihan
DOCX
Lecture4 oopj
DOCX
Lecture2 oopj
DOCX
Lecture5 oopj
DOCX
Lecture10 oopj
PPTX
Presentacion
Lecture7 oopj
Sistema Génesis y Portales Institucionales
Lecture6 oopj
Lecture3 oopj
02 Hidup ini Pilihan
Lecture4 oopj
Lecture2 oopj
Lecture5 oopj
Lecture10 oopj
Presentacion
Ad

Similar to Lecture1 oopj (20)

PPTX
Applets
PPT
Jsp applet
PPTX
Java Apple dndkorksnsbsjdkkdjejdjrdndjdj
PPT
Applets_Basic Introduction
PPT
Java: Java Applets
PPT
Unit 7 Java
PPT
Slide8appletv2 091028110313-phpapp01
PPT
Java programming Java programming Java programming
PPT
Advanced Programming, Java Programming, Applets.ppt
PPTX
Applet Programming in Advance Java Programming
PPTX
PPT
Applets
PPT
PPTX
Java applet
PPTX
java Applet Introduction
PDF
UNIT-1-AJAVA.pdf
PPT
Applet Architecture - Introducing Java Applets
PPTX
Applet.pptx
PPTX
Applet1 (1).pptx
PPTX
Applets in Java. Learn java program with applets
Applets
Jsp applet
Java Apple dndkorksnsbsjdkkdjejdjrdndjdj
Applets_Basic Introduction
Java: Java Applets
Unit 7 Java
Slide8appletv2 091028110313-phpapp01
Java programming Java programming Java programming
Advanced Programming, Java Programming, Applets.ppt
Applet Programming in Advance Java Programming
Applets
Java applet
java Applet Introduction
UNIT-1-AJAVA.pdf
Applet Architecture - Introducing Java Applets
Applet.pptx
Applet1 (1).pptx
Applets in Java. Learn java program with applets

Lecture1 oopj

  • 1. GUI IN JAVA  What is an Applet? Introduction Applet is java program that can be embedded into HTML pages. Java applets run on the java enables web browsers such as Mozilla and internet explorer. Applet is designed to run remotely on the client browser, so there are some restrictions on it. Applet can't access system resources on the local computer. Applets are used to make the web site more dynamic and entertaining. Advantages of Applet: Applets are cross platform and can run on Windows, Mac OS and Linux platform Applets can work all the version of Java Plug-in Applets are supported by most web browsers Applets are cached in most web browsers, so will be quick to load when returning to a web page User can also have full access to the machine if user allows Disadvantages of Java Applet: Java plug-in is required to run applet Java applet requires JVM so first time it takes significant start-up time If applet is not already cached in the machine, it will be downloaded from internet and will take time It’s difficult to design and build good user interface in applets compared to HTML technology Applet versus Application Applets as previously described, are the small programs while applications are larger programs. Applets don't have the main method while in an application execution starts with the main method. Applets can run in our browser's window or in an appletviewer. To run the applet in an appletviewer will be an advantage for debugging. Applets are designed for the client site programming purpose while the applications don't have such type of criteria. Applet is the powerful tools because it covers half of the java language picture. Java applets are the best way of creating the programs in java. There are a less number of java programmers that have the hands on experience on java applications. Applications are also the platform independent as well as byte oriented just like the applets.
  • 2. Applets are designed just for handling the client site problems. While the java applications are designed to work with the client as well as server. Applications are designed to exist in a secure area. While the applets are typically used. Applications and applets have much of the similarity such as both have most of the same features and share the same resources. Applets are created by extending the java.applet.Applet class while the java applications start execution from the main method. Applications are not too small to embed into a html page so that the user can view the application in your browser. On the other hand applet has the accessibility criteria of the resources. The key feature is that while they have so many differences but both can perform the same purpose.  The Life cycle of an Applet Introduction In this Section you will learn about the lifecycle of an applet and different methods of an applet. Applet runs in the browser and its lifecycle method are called by JVM when it is loaded and destroyed. Here are the lifecycle methods of an Applet: init( ) The init( ) method is the first method to be called. This is where you should initialize variables. This method is called only once during the run time of your applet. start( )
  • 3. The start( ) method is called after init( ). It is also called to restart an applet after it has been stopped. Whereas init( ) is called once—the first time an applet is loaded—start( ) is called each time an applet’s HTML document is displayed onscreen. So, if a user leaves a web page and comes back, the applet resumes execution at start( ). paint( ) The paint( ) method is called each time your applet’s output must be redrawn. This situation can occur for several reasons. For example, the window in which the applet is running may be overwritten by another window and then uncovered. Or the applet window may be minimized and then restored. paint( ) is also called when the applet begins execution. Whatever the cause, whenever the applet must redraw its output, paint( ) is called. The paint( ) method has one parameter of type Graphics. This parameter will contain the graphics context, which describes the graphics environment in which the applet is running. This context is used whenever output to the applet is required. stop( ) The stop( ) method is called when a web browser leaves the HTML document containing the applet—when it goes to another page, for example. When stop( ) is called, the applet is probably running. You should use stop( ) to suspend threads that don’t need to run when the applet is not visible. You can restart them when start( ) is called if the user returns to the page. destroy( ) The destroy( ) method is called when the environment determines that your applet needs to be removed completely from memory. At this point, you should free up any resources the applet may be using. The stop( ) method is always called before destroy( ).