开发者

Java Applets and html page - embedding multiple applets

开发者 https://www.devze.com 2023-03-24 05:22 出处:网络
I have just started to write applets and so have never embedded in a webpage before. 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 vi

I have just started to write applets and so have never embedded in a webpage before. 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. This seems very strange I have tried using the opening and closing foo bar tags for each applet.

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.

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="3开发者_Go百科50" 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. The reason I put the HTML in commas is because whatever that mess is pretending to be, it is not (valid) HTML.

(grumbles) Programmers tend to think that whatever rubbish they put in HTML should work. The real world is somewhat removed from this fantasy land.

Other recommendations:

  • Post a link to the applet, broken or otherwise. If we are feeling motivated, we can visit it, look at the (entire) HTML, download the Jars or classes, and test solutions.
  • Ensure the Java Console is opened automatically when loading applets. 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.


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. Use the APPLET tag's CODEBASE attribute to specify the folder that contains the 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:

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

0

精彩评论

暂无评论...
验证码 换一张
取 消