[Java] Passing parameters to Java applets

Problem

How to pass parameters to a Java applet?

Solution

You can specify the parameters in the calling HTML this way:

<applet code="my.Applet.class" width="600" height="400" >
    <param name="param1" value="value1" />
    <param name="param2" value="value2" />
</applet>

Then, the Applet class (from which your applet class extends) has a method getParameter(). In this case, getParameter("param1") would return the String "value1".

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s