Excreption Handling JavaApplets
Excreption Handling JavaApplets
Agenda
• Introduction
• Java Applet vs. JavaScript
• Steps in Creating a Java Applet
• Java Applet Example
• Do I have to write my own
• Summary
Introduction
• What is JAVA?
Java is an object oriented programming language created
by Sun Microsystems
Play Sound
Steps in Creating a Java Applet
• compile it
Steps in Creating a Java Applet
HEIGHT="22">
</applet>
……
</html>
08/01/25 12
Applet Execution - 2
• Life Cycle of an Applet:
– init: This method is intended for whatever
initialization is needed for an applet.
– 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. This method can be used to stop an
animation.
– destroy: This method is only called when the
browser shuts down normally.
– Ref: http://java.sun.com/docs/books/tutorial/deployment/applet/index.html/
08/01/25 13
Applet Execution - 3
• The applet is running and rendered
on the web page.
• Every Applet needs to implement one
of more of the init(), the start( ) and
the paint( ) methods.
• At the end of the execution, the
stop( ) method is invoked, followed
by the destroy( ) method to deallocate
the applet’s resources.
08/01/25 14
Applet Security
– Ref:
http://java.sun.com/docs/books/tutorial/deployment/applet/index.html /
08/01/25 15
HTML tags for applets - 1
<APPLET
// the beginning of the HTML applet code
CODE="demoxx.class"
// the actual name of the applet (usually a 'class' file)
CODEBASE="demos/"
// the location of the applet (relative as here, or a full URL)
NAME=“SWE622"
// the name of the instance of the applet on this page
WIDTH="100"
// the physical width of the applet on the page
HEIGHT="50"
// the physical height of the applet on the page
ALIGN="Top"
// align the applet within its page space (top, bottom, center)
08/01/25 16
HTML tags for applets - 2
<APPLET CODE=“SWE622.class" CODEBASE="example/"
WIDTH=460 HEIGHT=160
NAME="buddy" >
<PARAM NAME="imageSource" VALUE="images/Beans">
<PARAM NAME="backgroundColor" VALUE="0xc0c0c0"> <PARAM
NAME="endImage" VALUE=10>
</APPLET>
08/01/25 17
The HelloWorld Applet
<HTML> public void paint(Graphics g) {
<BODY> final int FONT_SIZE = 42;
<APPLET code=hello.class width=900 Font font = new Font("Serif",
height=300> Font.BOLD, FONT_SIZE);
</APPLET> // set font, and color and display
</BODY> message
</HTML> // on the screen at position 250,150
g.setFont(font);
// applet to display a message in a
g.setColor(Color.blue);
window
// The message in the next line is the
import java.awt.*; one
import java.applet.*; // you will see
g.drawString("Hello,
public class hello extends Applet { world!",250,150);
public void init( ) { } // end of paint()
setBackground(Color.yellow);
} // end of init() } // end of hello
08/01/25 18
Summary