Advertisement



< Prev
Next >



Applet Tag





Applet tag <applet> is required to load and start an applet either in a browser window or in an appletviewer(provided by JDK). At present, many current version of browsers such a Google Chrome and Mozilla Firefox(except Internet Explorer) have stopped displaying applets or recognizing <applet> tag, hence the only reliable tool to display an applet is appletviewer.

For those of you, who still wish to open an applet in a browser window need to read our article How to open an applet in an Internet Explorer browser




Note :


If a browser has stopped or restricted displaying applets, then it would just ignore the <applet> tag completely and an applet won't be loaded in the browser window.




Attributes of Applet tag


An applet tag contains many attributes that give you a good control over the your applet. Let's discuss some of these attributes :




  • CODE

  • This tag is used to specify the name of the your applet's .class file. This is a must required attribute in an <applet> tag.

    <applet code ="Applet1" width= 400 height=400>


    In this example, we have defined an applet whose compiled code is found within a file named "Applet1". This compiled .class file is searched in the same directory which contains Applet1.java file. The width and height of this applet will be 400 pixels each




  • WIDTH

  • This tag is used to specify the width of our applet window to be displayed within a browser or appletviewer. This is also a must required attitude in an <applet> tag. Width is specified in pixels.




  • HEIGHT

  • This tag is used to specify the height of our applet window in pixels, This is also a must required attribute in an <applet> tag.

    <applet code ="Applet1" width= 400 height=400>


    In this example, we have defined an applet whose compiled code is found within a file named "Applet1" and the width and height of this applet will be 400 pixels each


    Advertisement




  • NAME

  • This tag is used to give a name to an applet class and this name will be used when some other applet wish to communicate with this applet. This is also an optional attribute in <applet> tag.

    <applet code ="Applet1" width= 400 height=400 name = "firstApplet">
    </applet>


    In this example, we have defined an applet whose compiled code is found within a file named "Applet1". The width and height of this applet will be 400 pixels each and we are referring to this applet by the name "firstApplet", and this name will be used while communication with another applet.




  • CODEBASE

  • This tag is used to specify the directory location containing your applet's .class file.

    <applet code ="Applet1" width= 400 height=400 codebase ="http://MyWebsite.com//Folder">
    </applet>

    In this example, we have defined an applet whose compiled code is found within a file named "Applet1", which is found at the URL ""http://MyWebsite.com//Folder". This width and height of this applet will be 400 pixels each.




  • ALT

  • This tag is used to specify the text message that will be displayed in a situation when the browser has recognized the applet tag but it still cannot load the applet. This is an optional attribute in <applet> tag.

    <applet code ="Applet1" width= 400 height=400 alt ="Sorry, we can't load this applet>
    </applet>





  • PARAM

  • This is a sub-tag within <applet> tag and it is used to specify the parameters to be passed to an applet. This tag is an optional attribute within an <applet> tag.
      Two attributes within a <param> tag are :
    • name : This attribute is used to specify the name of the parameter passed to the applet.
    • value : This attribute is used to specify the value of the parameter passed to the applet.

    <applet code ="Applet1" width=400 height=400>
    <param name="City" value="Houston">
    <param name="Name" value="Roger"%gt;
    </applet>


    In this example, we have defined an applet whose compiled code is found within a file named "Applet1". This width and height of this applet will be 400 pixels each and we are passing two parameters to the applet. These parameters are named City and Name and their values are Houston and Roger.




  • VSPACE

  • This tag is used to specify the vertical space allotted above and below the applet window. VSPACE is specified in pixels and this is also an optional tag.

    <applet code ="Applet1" width= 400 height=400 VSPACE= 50>
    </applet>

    In this example, we have defined an applet whose compiled code is found within a file named "Applet1". This width and height of this applet will be 400 pixels each and the vertical space on its top and bottom sides will be 50 pixels.




  • HSPACE

  • This tag is used to specify the horizontal space on the either sides(right and left) of the applet window. HSPACE is also specified in pixels and this is also an optional attribute in the <applet> tag.

    <applet code ="Applet1" width= 400 height=400 HSPACE= 50>
    </applet>

    In this example, we have defined an applet whose compiled code is found within a file named "Applet1". This width and height of this applet will be 400 pixels each and horizontal space on its either sides will be 50 pixels.




  • ALIGN

This tag is used to specify how an applet will be aligned with respect to the surrounding content. ALIGN attribute takes any of the values : TOP, BOTTOM, LEFT, RIGHT, MIDDLE, ABSBOTTOM etc

<applet code ="Applet1" width= 400 height 4000 ALIGN= TOP>
</applet>


As per this example, our applet window will be aligned at the top of the sorrounding content.



Please share this article -



Advertisement

Please Subscribe

Please subscribe to our social media channels for daily updates.


Decodejava Facebook Page  DecodeJava Twitter Page Decodejava Google+ Page




Advertisement



Notifications



Please check our latest addition

C#, PYTHON and DJANGO


Advertisement