简体   繁体   English

Java Applets和html页面 - 嵌入多个applet

[英]Java Applets and html page - embedding multiple applets

I have just started to write applets and so have never embedded in a webpage before. 我刚刚开始编写applet,因此以前从未嵌入到网页中。 I have 2 applets that on there own run fine however when I try to run the 2 applets in the same page only one is visible. 我有2个小程序在那里运行正常然而当我尝试在同一页面中运行2个小程序时只有一个是可见的。 This seems very strange I have tried using the opening and closing foo bar tags for each applet. 这似乎很奇怪我尝试使用每个applet的打开和关闭foo bar标签。

These applets have no connection to each other however I also found that the html tags were also ignored after the applet which threw the page design out as well, this has totally baffled me. 这些小程序彼此之间没有任何联系,但是我也发现html标签在applet抛出页面设计之后也被忽略了,这让我很困惑。

The code encasing the applets is 包装小程序的代码是

<div class="wholeframe">
   <div class="lframe3">
       <!-- content for left frame to go here -->
       <h2>Basic Java Swing Applet</h2>
       <br />
       <applet code="org.my.form1.MyApplet" archive="java/form1gui/FormApplet1.jar"
               height="60" width="250"/> 
    </div>
    <div class="rframe">
       <h2>Basic Java Swing Applet</h2>

       <applet code="org.me.hello.MyApplet" archive="java/hello/HelloApplet.jar"
               width="350" height="150" /> 

      <!-- right frame div end -->
</div> <!-- whole frame to box 2 frames -->

I would be grateful if someone could advise where I have gone wrong as this should be simple to do and I am sure it is but I cannot seem to work out the issue. 如果有人可以告诉我哪里出错了,我会很感激,因为这应该很简单,而且我确信它是,但我似乎无法解决这个问题。

The first thing I'd recommend is validating that 'HTML' with the W3C mark-up validation service . 我建议的第一件事是使用W3C 标记验证服务验证“HTML”。 The reason I put the HTML in commas is because whatever that mess is pretending to be, it is not (valid) HTML. 我把HTML放在逗号中的原因是因为无论假装是什么混乱,它都不是(有效的)HTML。

(grumbles) Programmers tend to think that whatever rubbish they put in HTML should work. (抱怨)程序员倾向于认为他们在HTML中添加的垃圾应该有效。 The real world is somewhat removed from this fantasy land. 现实世界在某种幻想世界中有所消失。

Other recommendations: 其他建议:

  • Post a link to the applet, broken or otherwise. 发布指向applet的链接,已损坏或以其他方式。 If we are feeling motivated, we can visit it, look at the (entire) HTML, download the Jars or classes, and test solutions. 如果我们感到有动力,我们可以访问它,查看(整个)HTML,下载Jars或类,并测试解决方案。
  • Ensure the Java Console is opened automatically when loading applets. 确保在加载applet时自动打开Java控制台。 Without the console information, you are debugging this with 'one arm tied behind your back'. 如果没有控制台信息,您可以通过“一只手臂绑在背后”进行调试。
  • While debugging, reduce the web page to the minimum. 在调试时,将网页减少到最小。 No headers, divs, code, CSS etc. Include that stuff once it is working. 没有标题,div,代码,CSS等。一旦它工作,包括那些东西。

To embed more than one applet in a single web page, put each applet in its own subfolder within the folder that contains the HTML document. 要在一个网页中嵌入多个applet,请将每个applet放在包含HTML文档的文件夹中的自己的子文件夹中。 Use the APPLET tag's CODEBASE attribute to specify the folder that contains the applet. 使用APPLET标记的CODEBASE属性指定包含applet的文件夹。

For example, to embed the applets 'Aplt1' and 'Aplt2' in the web page defined by the file TestAplt.html, you can set up the following files and subfolders in a folder named Test: 例如,要将applet的“Aplt1”和“Aplt2”嵌入到文件TestAplt.html定义的网页中,您可以在名为Test的文件夹中设置以下文件和子文件夹:

 Test/TestAplt.html
 Test/Aplt1/<Class files for Aplt1> 
 Test/Aplt2/<Class files for Aplt2>

For files in this structure, put the following APPLET tags in the file TestAplt.html: 对于此结构中的文件,将以下APPLET标记放在TestAplt.html文件中:

<applet codebase="Aplt1/" code=Aplt1 width=16 height=400 align="left">
<param name=ParamAplt1 value="Aplt1.djr">
</applet>
<applet codebase="Aplt2/" code=Aplt2 width=32 height=400 align="right">
<param name=ParamAplt2 value="Aplt2.djr">
</applet> 

Please use this link Multiple applets in a page 请使用此链接页面中的多个小程序

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

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