Solved

Exchange arrays between Java applets and JavaScript functions?

Posted on 1997-05-13
5
186 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
sumDigits  challenge 7 62
count8 challlenge 13 87
mapShare challenge 13 69
Groovy:unable to resolve class error 2 31
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

760 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