0

我在 Eclipse 中构建项目 - swing 小程序,现在我正试图在浏览器中运行它。

我有 3 个包,假设它们被称为:带有 .class 文件的“pkgApplet”、“pkgFirst”、“pkgSecond”。在 pkgApplet 我有 class "main" with method main()。无论我做什么,我都无法在浏览器中运行这个小程序。目前我的 html 代码看起来像这样

<applet code="bin/pkgApplet/main" height="1000" width="1000"/>

无论我如何修改小程序标签,浏览器每次都会出现此错误:

NoClassDefFoundError with message bin/pkgApplet/main(wrong name: applet/main)

我尝试使用codebase属性,将小程序打包到 .jar 文件中并使用archive属性,但似乎没有任何效果。你知道我在做什么错吗?

4

1 回答 1

5

Your applet format should be:

<applet codebase="bin" code="pkgApplet.main" height="1000" width="1000"></applet>

bin is the default target directory (for Eclipse) so will require the codebase attribute as shown above. For this to work, your HTML file needs to be located in your project directory.

Note classes in Java start with uppercase, while package names are lowercase. Also its helpful to name classes describing what they do. You could have instead:

<applet codebase="bin" code="pkgapplet.MyMainApplet" height="1000" width="1000"></applet>

Do you realize that nothing in main will be called by your applet client? Any startup functionality should be placed in the init method.

于 2013-01-24T22:47:18.957 回答