The sample HTML file The listing below shows the source code for the sample HTML file we created for this article, including the applet tag shown.We name this file AppletParameterTest.html.
Java applet example - Passing applet parameters to Java applets
The ParamTest.java file So far we've seen to create the HTML code that (1) invokes a Java applet using an applet tag, and (2) passes parameters to the applet. Next, let's look at the Java applet code needed to read the parameters being passed to it. The next listing shows the Java code for the ParamTest.java file.
import java.applet.*;
import java.awt.*;
public class AppletParameterTest extends Applet {
public void paint(Graphics g) {
String myFont = getParameter("font");
String myString = getParameter("string");
int mySize = Integer.parseInt(getParameter("size"));
Font f = new Font(myFont, Font.BOLD, mySize);
g.setFont(f);
g.setColor(Color.red);
g.drawString(myString, 20, 20);
}
}