2. • 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
• For security reasons, applets run in a sandbox: they have no
access to the client’s file system
• Most modern browsers support Java 1.4 if they have the
appropriate plug-in
• A programmer should be able to write applets that can run on
any browser
3. Applet are not full featured application program. They are usually written to a
accomplish a small task or a component of a task. Since they are usually designed
for use on the internet, they impose certain limitation and restrictions in their
design .
1.Applets do not use the main() method for initiating the execution of the code.
Applets, when loaded, automatically call certain methods of Applet class to start
and execute the applet code.
2. Unlike stand-alone applications, applets can not be run independently. They
have to be embedded inside a web page to get using a special feature known as
HTML tag.
3. Applets can only be executed inside the web browser of appletviewer.
4. Applets can not read from or write to the files on the local computer
5. Applet can not communicate with the other servers on the network.
6. Applet can not run any program from the local computer.
7. Applet are restricted from using libraries from other languages such as C or C++.
(java language supports this feature through native methods)
5. Applets have 4 life cycle methods. They are:
init() – It is called to initialize the applet before it gets
loaded
start() – It is called to provide start up behavior
stop() – Called to stop any operations which are started
using start() method.
destroy() – Is called when an applet has finished execution.
6. ‘init’ and ‘destroy’ are only called
once each
‘start’ and ‘stop’ are called
whenever the browser enters and
leaves the page
‘do some work’ is code called by
your listeners
‘paint’ is called when the applet
needs to be repainted
7.
8. • Needed if you do any drawing or painting other than
just using standard GUI Components.
• Any painting you want to do should be done here, or in
a method you call from here.
• Painting that you do in other methods may or may not
happen.
• Never call paint(Graphics), call repaint( ).
9. 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)
10. g.drawString(“Hello”, 20, 20); Hello
g.drawRect(x, y, width, height);
g.fillRect(x, y, width, height);
g.drawOval(x, y, width, height);
g.fillOval(x, y, width, height);
g.setColor(Color.red);
15. ADVANTAGES
Applets are cross platform and can run on Windows, Mac OS and
Linux platform
Applets can work on all the versions of Java Plug-in.
Applet runs in a sandbox, so the user doesn’t need to trust the code
and it can work without security approval.
DISADVANTAGES:
Java Plug-in is required to run applet.
Java applet needs JVM so first time it takes significant start-up
time.
Difficult to design and build good user interface in applets
compared to other technologies.