Adding the Applet to Your Webpage
We now have a completed Java applet. We have compiled it into bytecodes so that it will run independent of platform. However, all this will do us no good if we do not attach the applet to a webpage.
The APPLET Tag
The first tag to add to your page is APPLET. After defining the applet, you declare any parameter you wish to pass to the applet. We will look at the PARAM tag next.
The attributes of the APPLET tag are:
- ALIGN=value
- Values can be LEFT, RIGHT, TOP, MIDDLE, or BOTTOM. ALIGN defines the horizontal alignment of the applet.
- ALT="message"
- If the applet cannot run for any reason, the ALT attribute defines text to be displayed on the webpage.
- ARCHIVE="class_file,class_file,..."
- If there are any class files that need to be preloaded, use the ARCHIVE attribute. If there are more than one file, separate them with commas.
- CODE="URL"
- This is the URL of the applet.
- CODEBASE="URL"
- This attribute is very similar to the BASE tag. It provides the URL of the applets for the webpage.
- HEIGHT=number
- This sets the height of the applet window.
- HSPACE=number
- This sets the horizontal space that surrounds the applet.
- NAME="name"
- This is the name of the applet.
- OBJECT="name"
- This is the name of a resource that contains the applet.
- VSPACE=number
- This is the vertical counterpart of HSPACE. This sets the vertical space around the applet.
- WIDTH=number_or_percentageofscreen
- This is the horizontal counterpart of HEIGHT. This sets the width of the applet window either in pixels or percentage of total screen width.
The PARAM Tag
You will probably want to pass information to the applet in the form of parameters. In DragonClock we pass a number to represent the value of the background and foreground colors. The parameters go between the <APPLET> and </APPLET> tags. The attributes of the PARAM tag are:
- NAME="name"
- This specifies the name of the parameter.
- VALUE=number_or_"text"
- This is the value assigned to the parameter. This is the value that will be passed to the applet.
- VALUETYPE=data_or_ref_or_object
- This specifies how to interpret the VALUE. VALUETYPE can be one of three possibilities:
- DATA - The default type. The value is data.
- REF - The value is a URL
- OBJECT - The value is the URL of an object.
- TYPE=type
- This specifies a MIMETYPE.
Putting It All Together
Here is the APPLET and PARAM tags for DragonClock:
Instructions for supplying the parameters are given in comment form so as not to show on the webpage.
Final Comments
Now we have talked briefly about Java and object oriented programming. We have written an applet to display a digital clock. And we have attached the applet to a webpage. That is all there is to it. There is much more to learn about Java and applets, but that is beyond the scope of this tutorial. Hopefully, by this time you have a better understanding of writing applets. May your code be plentiful and your bugs be few.
Java and java Development Kit are trademarks of Sun Microsystems.
All material is copyright of P & G Dragonsites and may not be reproduced in whole or in part in any media without prior permission.
For questions or comments please contact us at pgdragonsites@thecenter.zzn.com
Reprinted with permission from the author. Click here to visit the original version
Download this tutorial (~30 KB)
New on the Java Boutique:
New Review:
Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling
API boasts simplicity, ease-of-integration, a well-rounded feature
set, and it's free!
New Applet:
Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA
sequences into three useful formats.
Elsewhere on internet.com:
WebDeveloper Java
Lots of Java information on webdeveloper.com
WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.
ScriptSearch Java
Hundreds of free Java code files to download.
jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.
|