Applets with parameters
12 February 2008Applets may accept parameters. This post briefly shows how to do that.
Applet in included in HTML using APPLET tag. You have to specify the parameters in APPLET tag in the following form:
<APPLET CODE=AppletSubclass.class WIDTH=anInt HEIGHT=anInt>
<PARAM NAME=parameter1Name VALUE=aValue>
<PARAM NAME=parameter2Name VALUE=anotherValue>
</APPLET>Let me show you with an example:
<APPLET CODE="Animator.class" WIDTH=460 HEIGHT=160 ALT="If you could run this applet, you'd see some animation"> <PARAM NAME="imageSource" VALUE="images/Beans"> <PARAM NAME="backgroundColor" VALUE="0xc0c0c0"> <PARAM NAME="endImage" VALUE=10> <PARAM NAME="soundSource" VALUE="audio"> <PARAM NAME="soundtrack" VALUE="spacemusic.au"> <PARAM NAME="sounds" VALUE="1.au|2.au|3.au|4.au|5.au|6.au|7.au|8au|9.au|0.au"> <PARAM NAME="pause" VALUE=200> Your browser is completely ignoring the APPLET tag! </APPLET>
Now, applet will be send parameters and in the applet, we have to get them and have to act accordingly. Applet code to get the parameters is as follows:
int requestedWidth = 0; . . . String windowWidthString = getParameter("WINDOWWIDTH"); if (windowWidthString != null) { try { requestedWidth = Integer.parseInt(windowWidthString); } catch (NumberFormatException e) { //Use default width. } }
Play around and explore.
Related Posts:
- Java Applets - lifecycle - I
- Method signatures (I)
- An Introduction To Applets
- Fetching parms form web.xml - II
- Varargs – Java 5.0 addition
- Using pagging techniques - III
- Using pagging techniques - V
- Method parameters bounded by a Class
- Performance issues related to trigonometric functions , floating point arithmetic and JNI (II)
- Using tags in Struts(II)
Top Of Page | Trackback
If you found this page useful, consider linking to it. Simply copy and paste the code below into your web site.
It will look like this: Applets with parameters