PDA

View Full Version : referencing applets in NS4.78


glenngv
05-27-2003, 10:15 AM
<html>
<head>
<title>My Applet</title>
</head>
<body>
<form>
<applet width="450" height="200" code="MyApplet.class" name="myapplet" archive="MyApplet.jar" mayscript></applet>
<input type="button" value="Test" onclick="alert(document.applets['myapplet'])">
</form>
</body>
</html>

When I run the code in NS4.78, the applet loads and starts successfully. But when I click the Test button, it alerts undefined. I've tried document.myapplet but still undefined.

I've even tried embed tag instead of applet but to no avail, still undefined :(

<embed type="application/x-java-applet;version=1.4" width="450" height="200" code="MyApplet.class" name="myapplet" archive="MyApplet.jar" mayscript></embed>
<input type="button" value="Send" onclick="alert(document.embeds['myapplet'])">

Any idea?

Thanks! :)

glenngv
05-28-2003, 01:50 AM
I'm using Java Plug-in 1.4. The applet works as it should. But I cannot reference the applet in NS4.78. It's ok in IE and NS6.

realisis
05-28-2003, 05:09 AM
glenn, what answer do you get if you try document.applets[0]

or even document.applets.length

I just did a quick trial on NS4.7 (with another page), and was able to reference the applet by name and by index (although NS4 did did crash shortly thereafter, but I'm sure it's just a coincidence ;^]


Maybe it's an O/S thing? I'm on Win98SE...

If your page is online, I could load it in mine and check...

realisis
05-28-2003, 05:12 AM
another thought: try changing the applet's name and check again ... could it be that your applet's name is just a bit too similar to the .class and .jar filenames?

glenngv
05-29-2003, 02:17 AM
when I tried document.applets[0], javascript error occurred: no applet with index 9021544

when I tried document.applets.length, it alerts 0. :confused:

So it means that no applet is detected. Weird! The applet works as it should, no NS4 crash whatsoever. And I don't think it's because the applet's name is similar with the class and jar files. Actually, I renamed the class and jar files. The one I used in the sample is not the real files. But here in my environment (WinNT), I tried to rename the applet differently and the same error occurs.

any more ideas?

thanks realisis..

realisis
05-29-2003, 04:58 AM
no new ideas off the top of my head... there may a couple of things I could try from my computer, but I would need an online URL of your page...

too bad no solution with the last items...

glenngv
05-29-2003, 06:41 AM
Sorry but the page is not online. I will try to create a simple applet and test it...

Thanks for your time :)

glenngv
05-29-2003, 07:29 AM
I have created a simple applet and test pages using applet and embed tags. These are the codes and my results.
Im using Netscape 4.78/WinNT and Java Plug-in 1.4. In NS preferences, the "Enable Java" and "Enable Java Plugin" options are checked.

TestApplet.java

import java.applet.*;
public class TestApplet extends Applet
{
public void init(){
System.out.println("\nInitializing...");
}

public void start(){
System.out.println("Starting...");
}

public void stop(){
System.out.println("Stopping...");
}

public void destroy(){
System.out.println("Destroying...");
}
}


TestApplet.htm (Using applet tag):

<html>
<head>
<title>Using Applet Tag</title>
</head>
<body>
<form>
<p>Using applet tag:<br>
<applet width="450" height="200" code="TestApplet.class" name="myapplet" mayscript></applet><br>
<input type="button" value="Get Applets length" onclick="alert(document.applets.length)"><br>
<input type="button" value="Get Reference of Applet Using Name" onclick="alert(document.applets['myapplet'])"><br>
<input type="button" value="Get Reference of Applet Using Index" onclick="alert(document.applets[0])"></form>
</body>
</html>


TestApplet2.htm (using embed tag):

<html>
<head>
<title>Using Embed Tag</title>
</head>
<body>
<form>
Using embed tag:<br>
<embed type="application/x-java-applet;version=1.4" width="450" height="200" code="TestApplet.class" name="myembed" mayscript></embed><br>
<input type="button" value="Get Embeds length" onclick="alert(document.embeds.length)"><br>
<input type="button" value="Get Reference of Embed Using Name" onclick="alert(document.embeds['myembed'])"><br>
<input type="button" value="Get Reference of Embed Using Index" onclick="alert(document.embeds[0])">
</form>
</body>
</html>



Here are the results in NS4.78:

Using applet tag:
Get Applets length: 0
Get Reference of Applet Using Name: undefined
Get Reference of Applet Using Index: Javascript error occurs -> no applet with index 9021544 .

Using embed tag:
Get Embeds length: 1
Get Reference of Embed Using Name: undefined
Get Reference of Embed Using Index: Javascript error occurs -> unable to reflect embed with index 0 - not loaded yet?.

Maybe you could try these and see if you have the same results.
Thank you very much!!! :)

realisis
05-29-2003, 05:45 PM
Hi glenn,

After I woke up early this morning I thought the fact that your APPLET is nested in a form might be an issue... (certainly if you were using positioned content, it would be an issue) but then I tried nested in form with no problems... Also tried with and without the "mayscript" attribute, and no problem either way. Noticed also you're not using the "codebase" property - I'm guessing this does not need to be declared when applet in same folder as HTML file?

I've taken down your code statements down in note... will try a couple of essays later today.

I must confess I've not familiar with java though (have been using a third-party applet for test purposes) ... I'm assuming the import and void() statements should be saved to a file called "TestApplet.java" right?

Danne
05-29-2003, 06:31 PM
Hi Glenn, I found this piece of text in Core Servlets and JSP by Marty Hall (p. 274):

With JSP, you don’t need any special syntax to include ordinary applets: just
use the normal HTML APPLET tag. However, these applets must use JDK 1.1
or JDK 1.02 since neither Netscape 4.x nor Internet Explorer 5.x support the
Java 2 platform (i.e., JDK 1.2). This lack of support imposes several restrictions
on applets:
• In order to use Swing, you must send the Swing files over the
network. This process is time consuming and fails in Internet
Explorer 3 and Netscape 3.x and 4.01-4.05 (which only support
JDK 1.02), since Swing depends on JDK 1.1.
• You cannot use Java 2D.
• You cannot use the Java 2 collections package.
• Your code runs more slowly, since most compilers for the Java 2
platform are significantly improved over their 1.1 predecessors.

Furthermore, early browser releases had a number of inconsistencies in
the way they supported various AWT components, making testing and delivery
of complex user interfaces more burdensome than it ought to have been.
To address this problem, Sun developed a browser plug-in for Netscape and
Internet Explorer that lets you use the Java 2 platform for applets in a variety
of browsers. This plug-in is available at http://java.sun.com/products/
plugin/, and also comes bundled with JDK 1.2.2 and later. Since the
plug-in is quite large (several megabytes), it is not reasonable to expect users
on the WWW at large to download and install it just to run your applets. On
the other hand, it is a reasonable alternative for fast corporate intranets, especially
since applets can automatically prompt browsers that lack the plug-in to
download it.
Unfortunately, however, the normal APPLET tag will not work with the
plug-in, since browsers are specifically designed to use only their built-in virtual
machine when they see APPLET. Instead, you have to use a long and
messy OBJECT tag for Internet Explorer and an equally long EMBED tag for
Netscape. Furthermore, since you typically don’t know which browser type
will be accessing your page, you have to either include both OBJECT and
EMBED (placing the EMBED within the COMMENT section of OBJECT) or identify
the browser type at the time of the request and conditionally build the right
tag.

glenngv
05-30-2003, 02:49 AM
Thanks Danne for that article, I'll look into that. :)

realisis, I used mayscript attribute because the (actual) applet will access some javascript functions in the page. There is no codebase because the class file is in the same folder as the html. You must save the java code as TestApplet.java and compile it to produce TestApplet.class.

Again..Thanks for your time. :)


FYI, the applet (TestApplet.class) was tested with NS4.78, IE5.5, NS6, NS7 and Mozilla1.0. And it only failed in NS4.78 but only when referencing the applet. The applet loads and starts successfully in all the tested browsers including NS4.78.

I compiled the applet in JDK 1.4. Does that matter as what the article posted by Danne pointed out? But as you can see, I'm just printing out some text in the init(), start(), stop(), and destroy() methods. I did nothing that is only in JDK1.4.

glenngv
06-02-2003, 03:09 AM
can somebody test this for me? thanks! :)

realisis
06-02-2003, 07:30 PM
glenn,

Sorry for not getting back to this thread... My weekend was spent helping a neighbour move (end of month)...

I'll try once again to simulate the conditions you specified, however, I have no way of compiling the applet from the java code? (I have 1.4 on my computer, but not the JDK) ... So again I must use an existing .class file.

Probably won't be able to provide the definitive answer you're looking for, but I'll post again in a couple of hours.

realisis
06-02-2003, 10:22 PM
okay glenn, I tried several essays, with a couple of interesting details emerging, but no illuminating results.

Here's a rundown of my session for your reference:

BTW, dunno how this figures in to Danne's quoted passage, but:

when I load-up about : plugins in NS4, my list of plugins includes Java Plug-in 1.4.1_01, and Java Plug-in 1.3.1_02 ... NS4 seems to have no problem running these although admittedly the applet I tested was compiled in Java 1.1 (as per internal documentation). It's the only applet I have onboard at the moment.

Also BTW: my version of Netscape 4 is 4.7(0) not 4.78 or 4.79 ... As previously mentioned, I'm on WIN98SE.

***

APPLET essay:

I loaded up your HTML code, and substituted only the value of the code attribute (to reflect the applet I'm using). I still have absolutely NO PROBLEM accessing the applet by any of the properties discussed. I can even obtain a list of all the methods associated with the particular applet, and NS4 has no problem returning the results.

***

EMBED essay:

I loaded up your HTML code, and tried many variations, but got the same results you report for all three EMBED properties queried. I should point out that your onload alert was never invoked though, even though the status-bar reported "Applet myembed started" in most cases (though I tried also document.applets.length, and it also returned 0).

***

embed VARIATIONS TRIED (all with negative results):

I tried with the type attribute you specified, and also changed version to version=1.1 (to match the applet)

tried code attribute with ".class" specifed and then omitted and no difference (there shouldn't be a difference either way, but I was just checking)

also tried removing the type altogether, but then NS4 tried to connect to cgi.netscape.com

also tried referencing the .class file via the SRC attribute rather than the CODE attribute (since an EMBED is expecting a SRC, no??) - result in this case was "Applet myembed notinited" in statusbar, and a red X in the embed area, plus the usual query results.

tried removing the onload="alert()", since offhand I don't remember if embeds in NS4 even recognize the onload handler, and thought this might be what was hanging the execution, but no difference was made.

***

REALITY CHECK:

On a hunch I also loaded up a page with an embedded Quick-Time movie file: though NS4 runs the file with no problem, all the EMBED properties return the same negative results as the other cases above. I had a funny suspicion this would be the case.

SO: this suggests to me that maybe NS4 is simply buggy with embeds, and the desired properties are unavailable regardless of the plugin used?

***

That's about the best I can do right now. Hope this helps somewhat.

glenngv
06-03-2003, 02:30 AM
thank you very much realisis for the time! :)

I'll try to analyze your results later when I have time. I've got a busy sked ahead of me..

Thanks again! :thumbsup: