lecture1 oopj

4
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.

Upload: dhairya-joshi

Post on 22-Apr-2015

265 views

Category:

Documents


0 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Lecture1 oopj

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.

Page 2: Lecture1 oopj

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( )

Page 3: Lecture1 oopj

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( ).