applet
Get an applet parameter
This is an example of how to get an Applet parameter. A Java applet is a special kind of Java program that a browser enabled with Java technology can download from the internet and run. An applet is typically embedded inside a web page and runs in the context of a browser. An applet must be a subclass of the java.applet.Applet class. The Applet class provides the standard interface between the applet and the browser environment. Getting a parameter of an applet implies that you should:
- Create a class that extends the Applet, such as
GetAnAppletParameter
class in the example. - Use
init()
API method of Applet. This method is called by the browser or applet viewer to inform this applet that it has been loaded into the system. In this method callgetParameter(String name)
API method of Applet to get the value of a specified named parameter in the HTML tag.
Let’s take a look at the code snippet that follows:
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 | package com.javacodegeeks.snippets.core; import java.applet.Applet; public class GetAnAppletParameter extends Applet { private static final long serialVersionUID = -4164165523218431494L; // Called by the browser or applet viewer to inform // this applet that it has been loaded into the system. public void init() { String parameter1 = "param1" ; String value1 = getParameter(parameter1); String parameter2 = "param2" ; String value2 = getParameter(parameter2); } } |
1 2 3 4 5 | < applet code = "com.javacodegeeks.snippets.core.GetAnAppletParameter" width = "200" height="200'> < param name = "param1" value = "first param" > < param name = "param2" value = "second param" > </ applet > |
This was an example of how to get an Applet parameter in Java.