java applet显示字符串 该字符串的值要求在<Applet>标记中通过参数指定
1个回答
2013-11-15
展开全部
JAVA代码:
import java.applet.Applet;
import java.awt.Graphics;
public class Test extends Applet { // 定义主类
private String name; // 用于接收HTML参数的程序变量
private int num;
public void init() {
name = getParameter("varname"); // 接收HMTL中传递的参数
num = Integer.parseInt(getParameter("varnum"));
}
public void paint(Graphics g) {
g.drawString("Hello " + name + " ! Your are " + num + " years old.",
10, 20);
}
}
HTML代码:
<HTML>
<BODY>
<APPLET code="Test.class" height="60" Width="300">
<PARAM name="varname" value="Liu">
<PARAM name="varnum" value=30>
</APPLET>
</BODY>
</HTML>
import java.applet.Applet;
import java.awt.Graphics;
public class Test extends Applet { // 定义主类
private String name; // 用于接收HTML参数的程序变量
private int num;
public void init() {
name = getParameter("varname"); // 接收HMTL中传递的参数
num = Integer.parseInt(getParameter("varnum"));
}
public void paint(Graphics g) {
g.drawString("Hello " + name + " ! Your are " + num + " years old.",
10, 20);
}
}
HTML代码:
<HTML>
<BODY>
<APPLET code="Test.class" height="60" Width="300">
<PARAM name="varname" value="Liu">
<PARAM name="varnum" value=30>
</APPLET>
</BODY>
</HTML>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询