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 call getParameter(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:

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);

<applet code="com.javacodegeeks.snippets.core.GetAnAppletParameter"
		width="200" height="200'>
    <param name="param1" value="first param">
    <param name="param2" value="second param">

This was an example of how to get an Applet parameter in Java.

Byron Kiourtzoglou

Byron is a master software engineer working in the IT and Telecom domains. He is an applications developer in a wide variety of applications/services. He is currently acting as the team leader and technical architect for a proprietary service creation and integration platform for both the IT and Telecom industries in addition to a in-house big data real-time analytics solution. He is always fascinated by SOA, middleware services and mobile development. Byron is co-founder and Executive Editor at Java Code Geeks.
Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Inline Feedbacks
View all comments
Back to top button