Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Exchange arrays between Java applets and JavaScript functions?

Posted on 1997-05-13
5
Medium Priority
?
198 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 240 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

618 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