Java的嵌入到HTML [英] Java Embedding Into HTML

查看:196
本文介绍了Java的嵌入到HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我敢肯定,这个问题已经被问了一百万次,但无论我有多少谷歌搜索做,我不能得到这个工作。基本上,我试图让与它被嵌入在网页中的多个包的项目。我做这只是做了一些球,在屏幕上反弹,并能得到运行测试程序。我把主类在一个包,而在另一个球类只是为了测试它,它似乎运行正常。但是,我确实需要在一个网页(就叫FinalProject),程序会拒绝这样做。

I'm sure this question has been asked a million times, but no matter how many Google searches I do I cannot get this working. I'm basically trying to get a project with multiple packages in it to be embedded in a webpage. I made a test program which just made some balls bounce around the screen and was able to get that running. I put the main class in one package and the ball class in another just to test it and it seems to be running fine. But the program that I actually need in a web page (just called FinalProject) refuses to do it.

我可以得到它做的最好的事情就是给我一个空白屏幕,不给一个错误,但只是白色的。如果我尝试一下,它应该是什么也没有发生,我想是因为小程序是存在的,但只是显示白色,所以我不能看到它。我没有使用小程序标签,它从我的理解现在是很preciated但我需要把这个项目在网页上只是让老师可以看到它。我们已经测试过的其他人的项目(其中使用了小程序标记)的工作,所以我试图与坚持为现在和担心得到它在每个浏览器工作之后。虽然这很可能是这个问题。也许它会工作在他的浏览器,但这里不是我的。我试着运行我的谷歌Chrome,Mozilla Firefox浏览器和Internet Explorer程序,没有运气。

The best thing I can get it to do is give me a blank screen, without giving an error but just white. If I try clicking where it should be nothing happens, I think because the applet is there but is just showing white so I can't see it. I did use the applet tag, which from my understanding is now depreciated but I need to turn this project in on a webpage just so the teacher can see it. We've already tested that other people's projects (which used the applet tag) work, so I was trying to stick with that for now and worry about getting it working on every browser afterwards. Though that could very well be the problem. Maybe it would work on his browser but not mine here. I've tried running my program on Google Chrome, Mozilla Firefox, and Internet Explorer with no luck.

下面是HTML code:

Here is the HTML code:

<html>
<head>  

</head>  
<body>  
    <applet code = "main.FinalProject.class" width = "700px" height = "500px"></applet>  
</body>  
</html>

这是写在HTML文件中 [Eclipse工作区] /FinalProject/bin/test.htm 。在HTML中引用的FinalProject.class文件存在于 [Eclipse工作区] / FinalProject /斌/主/ FinalProject.class 。该FinalProject.class文件作为主类,所以我pretty肯定这是一个我需要运行。这是使用init一个()的actionPerformed(),涂料()方法和所有的好东西。

The HTML file this is written in is in [Eclipse Workspace]/FinalProject/bin/test.htm. The FinalProject.class file referenced in the HTML exists in [Eclipse Workspace]/FinalProject/bin/ main/FinalProject.class. The FinalProject.class file acts as the main class, so I'm pretty sure that's the one I need to run. It's the one with the init(), actionPerformed(), paint() methods and all that good stuff.

目前我想这个离线我的电脑上运行,因此不应该有任何净网址的,我觉得。我用Eclipse来编写Java code,不知道如果让任何区别。不幸的是,Java的code是相当大的,太多这里重现,如果有具体的你认为是问题,我可以看看,并张贴小部分东西。

Currently I'm trying to run this offline on my computer, so there shouldn't be any net URL's I would think. I used Eclipse to write the Java code, dunno if that makes any difference. Unfortunately, the Java code is rather large, too much to reproduce here, if there's something specific you think is the problem I can look and post that small section.

我的几个朋友设法让他们的工作,但他们说,他们不得不删除所有的.png文件(烦人,但可行为我的项目)。他们还表示,必须消除他们所有的鼠标移动code。我的计划是在那种依赖,我需要为它在所有的工作。我知道必须有使用网上所有的MouseListener和MouseMoveListener code的一种方式,也许这是一个有点不同,虽然。我不知道如果有什么与此有关,但我想我会指出来只是为了安全起见。

A few of my friends managed to get theirs working, however they said they had to remove all their .png files (annoying but doable for my project). They also said had to remove all their mouse movement code. My program is kind of dependent on that, I need that for it to work at all. I know there MUST be a way to use all the MouseListener and MouseMoveListener code online, maybe it's a little different though. I dunno if that has something to do with this, but I figured I'd point it out just to be safe.

在这里任何帮助将大大AP preciated。

Any help here would be greatly appreciated.

推荐答案

基本上你问的是这样的:<一href=\"http://stackoverflow.com/questions/985754/how-to-deploy-a-java-applet-for-todays-browsers-applet-embed-object\">How部署为今天的浏览器(小程序,嵌入,对象)?

Basically you're asking something like: How to deploy a java applet for today's browsers (applet, embed, object)?

在此基础上,我想你想要的是:

Based on that, I think what you want is:

<object 
  classid="clsid:CAFEEFAC-0015-0000-0000-ABCDEFFEDCBA"
  style="height: 500px; width: 700px;">
  <param name="code" value="FinalProject.class">
    <comment>
      <embed code="FinalProject.class"
        type="application/x-java-applet"
        height="500" width="700">
        <noembed>
          This browser appears to lack support for Java Applets.
        </noembed>
      </embed>
    </comment>
  </object>

现在,你有 main.FinalProject.class 的文件名,在code。这似乎是 FinalProject.class 将更有可能。但你可能是正确的。在任何情况下,这个HTML文件需要在同一文件夹 main.FinalProject.class FinalProject.class 并且还可能需要的任何类

Now, you have a filename of main.FinalProject.class in your code. It seems like FinalProject.class would be more likely. But yours could be right. In any case, this html file needs to be in the same folder as main.FinalProject.class or FinalProject.class and whatever classes may also be required.

现在,您可能还需要确保你的浏览器可以实际运行的小程序。请参阅:? 如何在我的网页浏览器中启用Java

Now, you may also need to make sure your browsers can actually run an applet. See: How do I enable Java in my web browser?

更新

根据安德鲁·汤普森preferred解决方案的反馈是使用JavaScript从甲骨文,像这样的:

Based on feedback from Andrew Thompson, the preferred solution is to use JavaScript from Oracle, like this:

<script src="http://www.java.com/js/deployJava.js"></script>
<script>
    var attributes = {
        code:'FinalProject.class',
    width:700, height:500} ;
    var parameters = {}; // does the Applet take parameters?
    var version = '1.6' ; // does the Applet require a minimum version of Java
    deployJava.runApplet(attributes, parameters, version);
</script>

这需要加载任意JavaScript的能力,但你也可以捕捉deployJava.js并具有在本地为好。可能是值得一试。

This requires the ability to load arbitrary JavaScript, but you could also capture that deployJava.js and have that be local as well. Might be worth a look.

这篇关于Java的嵌入到HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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