Applet 代码标签和类文件

发布于 2024-12-13 13:07:44 字数 896 浏览 0 评论 0原文

我刚刚开始编写 Applet,并且对带有包和类文件的 HTML Applet 标签有一些疑问。

我将从包开始。我一直在使用 Netbeans 来编写我的小程序,其中自动包含一个包。该小程序在 Netbeans 小程序查看器中运行良好,并且 HTML 正在显示除小程序之外的所有内容 - 只有一个白色框显示“错误”。当我使用不带包的 Eclipse 重新编译时,HTML 可以正常显示小程序。我尝试了我能想到的一切,但我终其一生都无法让小程序与该包一起工作。

<applet code="myClass.class"width="500"height="500">

<applet code="myPackage.myCLass.class"width="500"height="500">

<applet code="myPackage\myClass.class"width="500"height="500">

什么都没起作用。所以,我的第一个问题是:我的 HTML applet 标记路径应该说什么才能到达包中包含的 applet?老实说,我所有的谷歌搜索都产生了我并不真正理解的结果,因为我不能 100% 确定包是什么/做什么。

这引出了我的下一个问题:类文件。 applet标签指向一个类文件,即编译后的源文件。编译 .java 文件会创建 .class 文件,非常简单。但是如何从 applet java 文件转换为 applet 类文件呢?尝试通过命令行或任何 IDE 进行编译都会失败,因为没有 main 方法。到目前为止,我能够获取小程序的类文件的唯一方法是使用 Netbean 的小程序查看器或 Eclipse 中的“作为小程序运行”来编译代码。还有其他方法获取class文件吗?或者我是否必须使用小程序模拟器进行编译(因为缺乏更好的词)?

I just started writing Applets and I had some questions about the HTML applet tags with packages, and class files.

I'll start with packages. I've been using Netbeans to code my applets, which includes a package automatically. The applet runs fine in the Netbeans applet viewer, and the HTML is displaying everything it should except the applet - there's just a white box that says "Error." When I re-compiled using Eclipse without the package, the HTML display the applet fine. I tried everything I could think of, but I could not for the life of me get the applet to work with the package.

<applet code="myClass.class"width="500"height="500">

<applet code="myPackage.myCLass.class"width="500"height="500">

<applet code="myPackage\myClass.class"width="500"height="500">

Nothing worked. So, my first question is this: what should my HTML applet tag path say in order to get to an applet which is contained in a package? Honestly, all of my google searches yielded results that I didn't really understand, as I'm not 100% sure what a package is/does.

Which brings us to my next question: class files. The applet tag points a a class file, i.e., a compiled source file. Compiling a .java file creates a .class file, simple enough. But how does one get from an applet java file to an applet class file? Attempting to compile via the command line or any IDE fails, because there's no main method. So far, the only way that I've been able to get a class file for an applet is to compile the code either using Netbean's applet viewer or "Run as an applet" in Eclipse. Is there another way to obtain the class file? Or do I have to compile using an applet emulator (for lack of a better word)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

睫毛溺水了 2024-12-20 13:07:44
<applet code="myPackage.myCLass.class"width="500"height="500">

至于 myPackage 包中 myClass applet 类的 applet 元素。

1) applet 元素的属性之间应该有空格(我不确定这是否是 W3C 建议的一部分,但它看起来很奇怪)。

<applet code="myPackage.myCLass.class" width="500" height="500">

2) code 属性应该是类的完全限定名称,这意味着:

<applet code="myPackage.myCLass" width="500" height="500">

3) 如果没有指定存档和代码库,JRE 将在 myPackage 加载 HTML 的目录的子目录。 EG,如果 HTML 名为 applet.html 且位于:

该类需要位于:

一旦您认为小程序类正确,请尝试使用浏览器地址栏中的地址获取它。如果该类不提供下载,JRE 也将无法加载它。

<applet code="myPackage.myCLass.class"width="500"height="500">

As to the applet element for a myClass applet class in the myPackage package.

1) An applet element should have spaces between the attributes (I'm not sure if that is part of the W3C recommendation, but it just looks weird).

<applet code="myPackage.myCLass.class" width="500" height="500">

2) The code attribute should be the fully qualified name of the class, which means:

<applet code="myPackage.myCLass" width="500" height="500">

3) With no archives and no codebase specified, the JRE would look for the class in the myPackage sub-directory of the directory from which the HTML is loaded. E.G. if the HTML is called applet.html and is located at:

The class would need to be located at:

Once you think you have the applet class correct, try fetching it using the address in the browser address bar. If the class is not offered for download, the JRE won't be able to load it either.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文