Java applet Error … What is wrong?

醉酒当歌 提交于 2019-11-28 01:42:40

Problem is with the package. You need to change the code attribute of applet, and based on where you have placed your HTML, the codebase attribute too. You have to place HellowApplet.class in a directory called M257Applet (because that is the package you have given), and the applet tag should look something like:

<applet code="M257Applet.HellowApplet" ... ></applet>

For this to work, your HTML has to be in the same directory as M257Applet (not inside M257Applet). Alternatively, you can specify the codebase attribute. For eg, with the following directory structure:

somedir
  +-- hello.html
  +-- M257Applet
  |    +-- HellowApplet.class

the applet will work. If however, you had

anotherdir
  +-- hello.html
  +-- somedir
  |   +-- M257Applet
  |   |    +-- HellowApplet.class

then you will have to specify codebase attribute like so:

<applet code="M257Applet.HellowApplet" codebase="somedir" ... ></applet>

So, you should have codebase pointing to the directory containing your package, and code has to have your package name also in it.

Edit: Please note, even though code="HellowApplet.class" will work, the correct way of specifying the applet is without the ".class" at the end.

Tom Hawtin - tackline

Your class is in a package. It's file name should match.

code="M257Applet/HellowApplet.class"

(It's a good idea to follow conventions. Package names should be all lower case.)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!