Solved

Exchange arrays between Java applets and JavaScript functions?

Posted on 1997-05-13
5
187 Views
Last Modified: 2013-11-23
In a html-page I want to exchange arrays beetween JavaScript functions and Java applet functions.

I´ve tried the following code, but it returns with the script error
"No Java method matching arguments."

Here are my sample files:

JavaParameterTest.java

import java.applet.*;
public class JavaParameterTest extends Applet
{
      public JavaParameterTest()
      {
      }
      public String Test(String Ar[], int i) {
          return Ar[i];
      }
}

JavaParameterTest.html:

<html>
<head>
<title>JavaParameterTest</title>
<script>
testarray = new Array("Peter","Paul","Mary");
function test() {
  alert(document.JavaParameterTest.Test(testarray(),1));
}
</script>
</head>
<body onload="test();">
<applet
    code=JavaParameterTest.class
    name=JavaParameterTest
 </applet>
</body>
</html>

I there any chance to modify this code, so does it works on IE 3.0 and NS 3.0?

I would appreciate any help.
0
Comment
Question by:StephanM
  • 3
5 Comments
 

Expert Comment

by:NickRS051397
ID: 1220391
In the JavaScript you're trying to call a function testarray().
To pass an array use testarray[].
0
 

Author Comment

by:StephanM
ID: 1220392
Your proposal is not the right solution, because if I change
the argument for my applet from testarray() to testarray[],
it produces a syntax error in Netscape. Sorry.
0
 

Author Comment

by:StephanM
ID: 1220393
Adjusted points to 120
0
 
LVL 3

Accepted Solution

by:
garik earned 120 total points
ID: 1220394
1) JavaScript: add MAYSCRIPT tag to the applet to allow Java access to JavaScript objects; pass testarray as an object (not as function testarray()):
...
<script>
testarray = new Array("Peter","Paul","Mary");
function test() {
      alert(document.JavaParameterTest.Test(testarray,1));
}
</script>
</head>
<body onLoad='test();'>
<hr>
<applet      MAYSCRIPT
    code=JavaParameterTest.class
    name=JavaParameterTest
>
</applet>
...

2) Java: first argument to Test() is JSObject, so you have to import netscape.javascript.*; JSObject can't be casted to String[], but you can use JSObject.getSlot(index) to access individual members of the array:

import java.applet.*;
import netscape.javascript.*;
...
      public String Test(JSObject Ar, int i)
      {
            return (String)Ar.getSlot(i);
      }
...

3. MS IE: Not a chance. LiveConnect technology used here to communicate between Java and JavaScript is created by Netscape, implemented by Netscape, and works only on Netscape. Sorry.
For MS, you have to use MS staff, like Java-COM communications etc.
Wouldn't be nice to get rid of one of these big guys (I don't care which one) so that we could concentrate on contents and not on technical incompatibilities? Just a thought.

0
 

Author Comment

by:StephanM
ID: 1220395
Thanks for your response. I´ve checked it and it´s true -
there is in fact no chance to exchange arrays in the ie.

Concentrating on content and not on incompatibilities
would be nice, but I don´t think it will happen.

Over and out, StephanM.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
topping2 challenge 13 80
topping3 challenge 14 70
base64 decode encode 12 119
java stored proc example 9 20
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now