Applet 代码标签和类文件 [英] Applet code tags and class files

查看:18
本文介绍了Applet 代码标签和类文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始编写小程序,我对带有包和类文件的 HTML 小程序标记有一些疑问.

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

我将从包开始.我一直在使用 Netbeans 来编写我的小程序,它自动包含一个包.该小程序在 Netbeans 小程序查看器中运行良好,并且 HTML 显示了除小程序外应有的所有内容 - 只有一个显示错误"的白框.当我在没有包的情况下使用 Eclipse 重新编译时,HTML 可以很好地显示小程序.我尝试了所有我能想到的方法,但我终其一生都无法让小程序与包一起工作.

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">

没有任何效果.所以,我的第一个问题是:我的 HTML 小程序标记路径应该说些什么才能访问包含在包中的小程序?老实说,我所有的谷歌搜索都产生了我并不真正理解的结果,因为我不能 100% 确定包是/做什么.

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.

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

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)?

推荐答案

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

至于 myPackage 包中 myClass 小程序类的 applet 元素.

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

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

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) code 属性应该是类的全限定名,意思是:

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

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

3) 在没有指定存档和代码库的情况下,JRE 将在加载 HTML 的目录的 myPackage 子目录中查找该类.例如.如果 HTML 被称为 applet.html 并且位于:

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:

该类需要位于:

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

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.

这篇关于Applet 代码标签和类文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆