Passing Parameters to Applets

With Java applications, you can pass parameters to the main() method by using arguments on the command line. You then can parse those arguments inside the body of your class, and the application acts accordingly based on the arguments it is given.

Applets, however, don't have a command line. Applets can get different input from the HTML file that contains the <APPLET> or <OBJECT> tag through the use of applet parameters. To set up and handle parameters in an applet, you need two things:

  • A special parameter tag in the HTML file

  • Code in your applet to parse those parameters

Applet parameters come in two parts: a name, which is simply a name you pick, and a value, which determines the value of that particular parameter. ...

Get Sams Teach Yourself Java 2 in 21 Days, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.