Applet
Applet
Applet
Applets
Introduction
Local & Remote Applets
How Applets differ from Applications
When to use applets
Applet Life Cycle
Applet Restrictions
Applet Programming
Introduction
Types of Java Programs
• e.g. the applet context might decide to make the applet inactive if
the applet is scrolled out of view.
• Or, it might make the applet inactive if the user views another
document and leaves the document with the applet.
Initialization
Begin Born
(Load Applet)
start() stop()
Dead End
Destroyed
/* Applet description. */
</HTML>
Adding Applet to HTML File
<HTML>
<! Web page displaying Title, Message and
specifying the applet to be loaded & executed.>
<HEAD>
<TITLE> Welcome to Java Applets </TITLE>
</HEAD>
<BODY>
<CENTER>
<H1> Welcome to the World of Applets </H1>
<BR>
</CENTER>
<CENTER>
<APPLET
CODE = HelloJava.class
WIDTH = 400
HEIGHT = 200>
</APPLET>
<CENTER>
</BODY>
</HTML>
Running the Applet
If we use the appletviewer tool, we will only see the applet output.
The appletviewer is not a full-fledged Web browser.
We can use it to run our applet as follows :
appletviewer HelloJava.html
Applet Tag with all attributes
<APPLET
[ CODEBASE = codebase_URL ]
CODE = AppletFileName.class
[ ALT = alternate_text ]
[ NAME = applet_instance_name ]
WIDTH = pixels
HEIGHT = pixels
[ ALIGN = alignments ]
[ VSPACE = pixels ]
[ HSPACE = pixels ]
>
[ < PARAM NAME = name1 VALUE = value1> ]
[ < PARAM NAME = name2 VALUE = value2> ]
…………………….
…………………….
</APPLET>
Passing Parameters to Applets
We can define the init() method in the applet to get hold of the
parameters defined in the <PARAM> tags.
1.AppletContext
2.AppletStub
3.AudioClip
The java.applet Package
Checkboxes(java.awt.Checkbox)
Labels (java.awt.List)
Menus(java.awt.Menu,java.awt.MenuItem,java.awt
.CheckboxMenuItem)
Containers (java.awt.Panel, java.awt.Window)
FlowLayout
GridLayout
BorderLayout
CardLayout
GridBagLayout
Example FlowLayout Manager
public FlowLayout()
Constructs a new FlowLayout with a default
center alignment and a default gap of five pixels
for both horizontal and vertical.
GridLayout Manager
The GridLayout manager arranges components
in a grid (matrix) formation with the number of
rows and columns defined by the constructor. The
components are placed in the grid from left to
right starting with the first row, then the second,
and so on.
GridLayout Constructors