4 Applets
4 Applets
Applets
Applets
An applet is a Panel that allows interaction
with a Java program.
A applet is typically embedded in a Web page
and can be run from a browser.
You need special HTML in the Web page to
tell the browser about the applet.
Applets run in a sandbox: they have no access
to the clients file system.
Applet Support
Netscape claims to support Java 1.1, but has
serious omissions.
MS Internet Explorer supports most of 1.1.
The best support isn't a browser, but the
standalone program appletviewer.
In general you want to write applets that
can be run with any browser
What an applet is
You write an applet by extending the class
Applet.
Applet is just a class like any other; you
can even use it in applications if you want.
When you write an applet, you are only
writing part of a program.
The browser supplies the main program.
Applet methods
public void
public void
public void
public void
public void
init ()
start ()
stop ()
destroy ()
paint (Graphics g)
repaint( )
Call repaint( ) when you have changed
something and want your changes to show up
on the screen
repaint( ) is a request--it might not happen.
When you call repaint( ), Java schedules a
call to update(Graphics g).
update( )
When you call repaint( ), Java schedules a call to
update(Graphics g)
Here's what update does:
BODY
TITLE
(content)
Most HTML
tags are
containers.
A container is
<tag> to
</tag>
HTML
<html>
<head>
<title> Hi World Applet </title>
</head>
<body>
<applet code="HiWorld.class
width=300 height=200>
<param name=arraysize value=10>
</applet>
</body>
</html>
The End