Applets
What is a Java Applet?
Java is an object-oriented programming language developed by Sun Microsystems. One of the greatest things about the fact that Java is object oriented is the standard library of objects it provides. These objects are easy to use and rich with functionality. A Java program is executed as either an application which runs stand-alone from the command line or as an applet that runs under a Web browser. Applications and applets start program execution in different ways; an application has a main() method and an applet has a init() method inititiated by the browser. This article will focus on writing an applet.
How do you execute a Java Applet?
The source code of a Java applet is stored in file with the suffix ".java". The source code is compiled into bytecode and stored in a file with the suffix ".class". The ".class" file is included in the HTML document using the applet tag. Here is an example of the applet tag used by the Contact applet:
<APPLET CODE="Contact.class" WIDTH=170 HEIGHT=150>
A Java applet is executed by a Web browser when the browser loads an HTML document that contains an applet tag. The Contact applet source code is stored in Contact.java. Its bytecode is stored in Contact.class . It is included in the Contact.html document.
The applet tag defines the width and height of the applet window within the HTML document. The applet tag has numerous
attributes to enhance its placement within the HTML document.
|