Applet Tag by Example
Here is an example of the code we could use to place the Hello applet we created previously in a web page:
<APPLET WIDTH = "200" HEIGHT = "100"
CODE = "Hello.class">
</APPLET>
Notice that we gave the applet a specific width and height.
For an applet to appear, you must give it a specific width and height.
If you don't want an applet to display (such as when your applet creates a popup frame right away), you can give it a width and height of 0:
<APPLET WIDTH = "0" HEIGHT = "0"
CODE = "HelloAwtApplet.class">
</APPLET>
However, normally you will want your applet to appear.
In our case, we want the applet to be 200 by 100 pixels.
Here is a full example of an HTML page we could use to display our Hello applet example.
<HTML>
<HEAD>
<TITLE>Hello</TITLE>
</HEAD>
<BODY>
The Hello applet appears below:
<P>
<APPLET WIDTH = "200" HEIGHT = "100"
CODE = "HelloAwtApplet.class">
</APPLET>
</BODY>
</HTML>
NEXT
Selena Sol contributes to the JavaBoutique's Introduction to Java. Selena curently works for Barclays Capital in London, one of the leading global investment banks in Europe and has worked as a software developer for the National Center for Human Genome research, Microline Software, Neuron Data, and Electric Eye in Singapore. Selena is perhaps best-known for creating the Public Domain Web Script Archive (Extropia) and writing several books on Web Programming (Perl, CGI, Java).
Email: selena@extropia.com
|