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

x
?
Solved

Passing a value toJavaScript

Posted on 1998-08-10
4
Medium Priority
?
191 Views
Last Modified: 2010-04-16
I want to create a slider in java which can be used to pass a value to a javascript function located on the same page at the Applet.

Is this possible, and if so how.
0
Comment
Question by:RICHARDH
[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
4 Comments
 
LVL 28

Accepted Solution

by:
sybe earned 100 total points
ID: 1232256
I have just answered a similar question, so I'll repeat my answer here.


    sample code for the applet:
    ===========================
    import java.applet.*;
    import netscape.javascript.JSObject;

    public class JSObjectTest extends Applet {
       JSObject mozilla;
       String[] args;
       String msg;

       public void init() {
          msg = getParameter("msg");
          try {
             mozilla = JSObject.getWindow(this);
          }
          catch (NoClassDefFoundError e) {}

          String args[] = {msg + ""};
          try {
             mozilla.call("setVar", args);      
          }
          catch (NoClassDefFoundError e) {}
       }

    }

    =========================================

    sample code for HTML/Javascript:

    =========================================
    <HTML>
    <HEAD>
    <title>JSObjectTest.java</title>

    <script language="JavaScript">
    <!--
    function setVar(msg){
    alert(msg);
    }
    // -->
    </script>


    </HEAD>
    <BODY BGCOLOR="#FFFFFF">

    <applet name="jsobjecttest" code="JSObjectTest.class" width=2 height=2 MAYSCRIPT>
    <param name="msg" value="Your browser supports Java to JavaScript using the JSObject class">
    </applet>

    </BODY>
    </HTML>
    ======================================

    Note that the applet passes the parameter "msg" (in the applet tag) to the javascript function SetVar.

    That function is in this case an alert. But it could be anything like document.bgcolor, document.location etc.
0
 

Author Comment

by:RICHARDH
ID: 1232257
For the attention of sybe...
Many, many thanks for a very precise answer. I have one further question.

Where do I get the Netscape.javascript class which is imported into the Applet.

Thanks again
0
 
LVL 28

Expert Comment

by:sybe
ID: 1232258
If you have netscape (3+) installed, you should add the path to the netscape java classes into the CLASSLIB environment variable.

You can easily view the netscape classes by making a copy of it and renaming that copy to *.zip. Then you can open it using winzip.

If you have MSIE4 installed you will find it under one of the directories of C:\windows\java.

If you have found the right zip containing JSObject.class then add it to the CLASSLIB environmental variable:


something like:

CLASSLIB = C:\JDK\LIB\CLASSES.ZIP;C:\NETSCAPE\NAVIGATOR\PROGRAM\JAVA\CLASSES\java_30


0
 
LVL 28

Expert Comment

by:sybe
ID: 1232259
sorry, CLASSLIB should be CLASSPATH
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
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.
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