无法在浏览器中运行此小程序代码

时间:2019-03-11 18:58:25

标签: java applet awt

在Java课程中,我正在学习applet。我必须用awt来做。为了运行该applet,我首先编写了以下代码,并将其编译为MyApplet.class文件,还将RunApplet.html文件放在MyApplet.class文件的同一目录中。

import java.applet.*;
import java.awt.*;

public class MyApplet extends Applet{
    public int x,y,w,h;
    public void init(){
        x=Integer.parseInt(getParameter("xValue"));
        y=Integer.parseInt(getParameter("yValue"));
        w=Integer.parseInt(getParameter("wValue"));
        h=Integer.parseInt(getParameter("hValue"));
    }
    public void paint(Graphics g){
        g.drawRect(x,y,w,h);
    }

}

RunApplet.html文件是:

<html>
<body>
<applet code="MyApplet.class" width="150" hight="100">
    <param name = "xValue" value = "20">
    <param name = "yValue" value = "40">
    <param name = "wValue" value = "100">
    <param name = "hValue" value = "50">
</applet>
</body>
</html>

但是,当我使用浏览器运行html文件时,它既未显示任何applet,也未显示任何错误消息。有人可以帮我吗?

0 个答案:

没有答案
相关问题