简体   繁体   English

多类Java小程序

[英]Multi Class Java Applet

I'm using Eclipse for my code, and my package name is com.neelsomani.rocketman. 我正在使用Eclipse作为我的代码,我的包名是com.neelsomani.rocketman。

I'm not sure how to properly upload my Java applet. 我不确定如何正确上传我的Java小程序。 So far I have two classes in the same .java. 到目前为止,我在同一个.java中有两个类。 I compile my code, then look in bin/com/neelsomani/rocketman . 我编译我的代码,然后查看bin/com/neelsomani/rocketman There are four .class files there. 那里有四个.class文件。 There is RocketMan$1.class , RocketMan.class , RocketMan$2.class , and RocketMan$Meteor.class . RocketMan$1.classRocketMan.classRocketMan$2.classRocketMan$Meteor.class

I tried uploading all of these to my website but it didn't work. 我尝试将所有这些上传到我的网站,但它没有用。 I used RocketMan.class for the code attribute of the applet tag. 我使用RocketMan.class作为applet标记的代码属性。 Here is the link to the page: http://www.theawesomenesssite.com/applet/rocketman.php . 以下是该页面的链接: http//www.theawesomenesssite.com/applet/rocketman.php

You can view the way I uploaded the files here: http://www.theawesomenesssite.com/applet/ . 您可以在此处查看我上传文件的方式: http//www.theawesomenesssite.com/applet/

I keep my images folder in the bin folder on my Mac and it runs fine. 我将我的images文件夹保存在Mac上的bin文件夹中,运行正常。 Is there some place that I should be putting the folder on my site? 是否有一些地方我应该把文件夹放在我的网站上?

Thanks. 谢谢。

Neel 尼尔

you've specified the classname incorrectly. 你错误地指定了类名。 Needs to be the fully qualified name ie. 需要成为完全合格的名称,即。 include the package and class name. 包括包和类名。 It expects the class name, not the class filename 它需要类名,而不是类文件名

<applet width=400 height=400 code="com.neelsomani.rocketman.RocketMan"> </applet>

You also need to upload the class files (you need all of them) in the same directory structure as the package path. 您还需要在与包路径相同的目录结构中上载类文件(您需要所有这些文件)。 So in your case your classes should be in 所以在你的情况下你的课程应该在

http://www.theawesomenesssite.com/applet/com/neelsomani/rocketman

If you don't want to upload the .class files individually (and the browser/plugin download them individually), you could also put them in a jar file, in the directory structure given by the package structure, like this: 如果你不想单独上传.class文件(并且浏览器/插件单独下载它们),你也可以将它们放在一个jar文件中,在包结构给出的目录结构中,如下所示:

  • rocketman.jar rocketman.jar
    • com COM
      • neelsonmani neelsonmani
        • rocketman 火箭人
          • RocketMan$1.class ROCKETMAN $ 1.class
          • RocketMan.class RocketMan.class
          • RocketMan$2.class ROCKETMAN $ 2.class
          • RocketMan$Meteor.class ROCKETMAN $ Meteor.class

For the images, you can put them in the same jar file - but make sure you load them in the applet with Class.getRessource() or related functions, not as a file. 对于图像,您可以将它们放在同一个jar文件中 - 但请确保使用Class.getRessource()或相关函数将它们加载到applet中,而不是作为文件加载。

Then use the archive attribute for your <applet> tag. 然后使用<applet>标记的archive属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM