How do I create an applet that accepts an unlimited number of parameters?

John Zukowski

While there is some upper bounds to the number of parameters the browser will let you specify, if you would like to let a user specify an undefined number of values, you can let them specify a parameter with a number at the end and keep counting until no more parameters following that pattern are there, as in:

<applet code=Params width=10 height=10>
<param name=Param0 value=Hello>
<param name=Param1 value=World>
</applet>

To do this, you just increment a counter for the getParameter() calls:

import java.applet.*;

public class Params extends Applet {
  public void init() {
    String value;
    int i = 0;
    while ((value = getParameter("Param" + i)) != null) {
      System.out.println ("Param" + i + ": " + value);
      i++;
    }
  }
}
0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact