Applet Architecture - Introducing Java Applets

amitksaha 33,796 views 17 slides Sep 23, 2007
Slide 1
Slide 1 of 17
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17

About This Presentation

A back-to-basic presentation on Java applets


Slide Content

23/09/07 Applet Architecture -Amit K. Saha 1
Applet Architecture
Amit Kumar Saha
B.Tech. (3
rd
year,Computer Science & Engineering)
College Roll No. 04/CS/20
Department of Computer Science & Informatics
Haldia Institute of Technology
Haldia
Presenting Java Applets

23/09/07 Applet Architecture -Amit K. Saha 2
What are Applets?
”Applets are small applications that are accessed on an Internet
Server, transported over the Internet, automatically installed,and run
as part of a Web document” , (Schildt , Herbert ”Java 2: The
complete Reference,2001)
An applet is a program written in the Java programming language
that can be included in an HTML page, much in the same way an
image is included in a page. When you use a Java technology-
enabled browser to view a page that contains an applet, the applet's
code is transferred to your system and executed by the browser's
Java Virtual Machine (JVM) (http://java.sun.com/applets/)

Functional Diagram of Applets

23/09/07 Applet Architecture -Amit K. Saha 4
Applet Architecture
Event driven
An applet waits until an event occurs.
The AWT notifies the applet about an event by calling event handler
that has been provided by the applet.The applet takes appropriate
action and then quickly return control to AWT

All Swing components descend from the AWT Container class

User initiates interaction with an Applet (and not the other way
around)

23/09/07 Applet Architecture -Amit K. Saha 5
The Applet API
The API is provided by the javax.swing.JApplet class and the
java.applet.AppletContext interface. (Java SE 6)
Applets can use these APIs to do the following:
Be notified by the browser of milestones.
Load data files specified relative to the URL of the applet or the
page in which it is running.
Make the browser display a document.
Find other applets running in the same page.

Play sounds.

23/09/07 Applet Architecture -Amit K. Saha 6
Life cycle of an Applet
init: This method is intended for whatever initialization is needed for your
applet. It is called after the param attributes of the applet tag.
start: This method is automatically called after init method. It is also called
whenever user returns to the page containing the applet after visiting other
pages.
stop: This method is automatically called whenever the user moves away from
the page containing applets. You can use this method to stop an animation.
destroy: This method is only called when the browser shuts down normally
Thus, the applet can be initialized once and only once, started and stopped one or
more times in its life, and destroyed once and only once.

23/09/07 Applet Architecture -Amit K. Saha 7
Methods for Milestones
Following is the interface for these methods:
public class Simple extends JApplet {
. . .
public void init() { . . . }
public void start() { . . . }
public void stop() { . . . }
public void destroy() { . . . }
. . .
}
Not every applet needs to override every one of these methods.
Some very simple applets override none of them.

Applet Skeleton
public class Simple extends JApplet {
. . .
public void init() { . . . }
public void start() { . . . }
public void stop() { . . . }
public void destroy() { . . . }
public void paint (Graphics g){.. }
. . .
}
In some situations the Applet may override the method update( )
Applets do not need a main( ) method
Applets must be run under an applet viewer or a Java-compatible browser
User I/O is not accomplished with Java’s stream I/O classes. Instead, applets use the
interface provided by the AWT

Program Execution Flow

Handling Events
Applets inherit a group of event-handling methods from the
Container class
The Container class defines several methods, such as
processKeyEvent and processMouseEvent, for handling
particular types of events, and then one catch-all method
called processEvent
To react to an event, an applet must override the
appropriate event-specific method

UI Components
Swing supplies the following UI components (the class that implements
each component is listed in parentheses):
Buttons (javax.swing.JButton)
Checkboxes (javax.swing.JCheckBox)
Single-line text fields (javax.swing.JTextField)
Larger text display and editing areas (javax.swing.JTextArea)
Labels (javax.swing.JLabel)
Lists (javax.swing.JList)
Pop-ups (javax.swing.Popup)
Scrollbars (javax.swing.JScrollBar)
Sliders (javax.swing.JSlider)
Drawing areas (java.awt.Canvas)
Menus (javax.swing.JMenu,javax.swing.JMenuBar javax.swing.JMenuItem,
javax.swing.JCheckBoxMenuItem)
Containers (javax.swing.JPanel, javax.swing.JWindow and its subclasses)

Methods for UI Components
add
Adds the specified Component
remove
Removes the specified Component
setLayout
Sets the layout manager

23/09/07 Applet Architecture -Amit K. Saha 13
Deploying Applets
Deploying Applets on the Internet Versus an Intranet
Use the <applet> tag if the Web page is accessed through the
Internet, or if it is accessed through an Intranet in which people use
different browsers.
Use the <object> or <embed> tag if the Web page is accessed
through an Intranet and you know which browser people use
Deploying Applets for Specific Browsers
For Internet Explorer only, use the <object> tag.
For the Mozilla family of browsers only, use the <embed> tag

23/09/07 Applet Architecture -Amit K. Saha 14
Practical Considerations
Security Restrictions
Applets cannot load libraries or define native methods.
An applet cannot start any program on the host that is executing it.
An applet cannot make network connections except to the host that it came from
Threads in Applets
Applets are generally multi-threaded – one thread builds up the UI while the other
fetches data or does some background processing
Working with a server-side application

….recap
What are Applets?
Architecture of Applets
Applets API
Deploying Applets
Applets & Security

References
“Java 2 : The Complete Reference”,
Schildt, Herbert, TMH, 2001
http://java.sun.com

23/09/07 Applet Architecture -Amit K. Saha 17
Thank You
Tags