简体   繁体   English

我想在HTML中运行Java Applet,但始终存在错误

[英]I want to run java applet in HTML, but it allways have bug

I try from a long time ago to launch Java applets in browser (they are simple games). 我很久以前就尝试在浏览器中启动Java applet(它们是简单的游戏)。 For a long time it say out-of-date Java version (now have the latest version 8 update 45), even after I install the latest before 2 min. 很长一段时间,即使我在2分钟之前安装了最新版本,它仍说Java版本已过期(现在有最新版本8更新45)。 NVM, I hope I fixed it. NVM,我希望我修复它。 Now it say a lot of different errors: runtime exception or AccessControlExeption for ex. 现在,它会说很多不同的错误:运行时异常或ex的AccessControlExeption

I am running this programs in Eclipse and I tried them, so they work. 我正在Eclipse中运行此程序,并尝试了它们,因此它们可以正常工作。 Maybe I have a problem with HTML code. 也许我的HTML代码有问题。

    <!DOCTYPE html>
<html>
    <head>
        <link rel="stylesheet" href="styles.css">

    </head>
    <body>
        <canvas id="canvas-id" ></canvas>
    </body>

    <applet width="600" height="170" code="theLightRoute.class"></script>
    </applet>
</html>

First : your HTML code is not valid, remove the </script> closing tag inside your <applet/> section. 首先 :您的HTML代码无效,请删除<applet/>部分中的</script>结束标记。 Even if some browsers can accept it, I don't think you can expect to have a valid result with an invalid tag definition. 即使某些浏览器可以接受它,我也不认为您会期望获得带有无效标签定义的有效结果。

Second : the <applet/> tag support can vary regarding the browser (see http://www.w3schools.com/tags/tag_applet.asp ). 其次<applet/>标记支持在浏览器方面可能有所不同(请参阅http://www.w3schools.com/tags/tag_applet.asp )。 You should try with <object/> instead (see http://www.w3schools.com/tags/tag_object.asp ) 您应该改用<object/> (请参阅http://www.w3schools.com/tags/tag_object.asp

Third : you cannot expect anymore that any modern web browser will support a java applet, whatever the tag you use. 第三 :您再也不能期望任何现代Web浏览器都支持Java applet,无论您使用什么标签。 Indeed, most of them have dropped or disabled by default the browser-side support of any java applet for security reasons. 实际上,出于安全原因,大多数默认情况下已删除或禁用了所有Java applet的浏览器端支持。 For example for Chrome 42, the java support is totally dropped: http://www.infoq.com/news/2015/04/chrome-42-npapi . 例如,对于Chrome 42,完全不支持Java支持: http : //www.infoq.com/news/2015/04/chrome-42-npapi For Firefox or safari it should be enabled manually https://support.mozilla.org/en-US/kb/how-allow-java-trusted-sites ). 对于Firefox或safari,应手动启用https://support.mozilla.org/en-US/kb/how-allow-java-trusted-sites )。

Actually, there is no good reason to create some java applet anymore , it's a totally deprecated and obsolete technology ( https://softwareengineering.stackexchange.com/questions/154537/do-java-applets-have-any-place-on-the-web-today ). 实际上, 现在没有充分的理由再创建一些Java applet ,这是一种完全不推荐使用且过时的技术( https://softwareengineering.stackexchange.com/questions/154537/do-java-applets-have-any-place-on-今天的网络 )。

Try to learn HTML5 for game programming instead :-) Many courses exist and can help you, and many HTML5 game engine are available ( http://html5gameengine.com/ ). 尝试改为学习HTML5进行游戏编程:-)存在许多课程,可以为您提供帮助,并且可以使用许多HTML5游戏引擎( http://html5gameengine.com/ )。 And it is cross-platform, mobile included! 它是跨平台的,包括移动设备!

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

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