Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6736853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:10:45+00:00 2026-05-26T11:10:45+00:00

I’m trying to convert a complex Java applet to JavaScript. The applet does all

  • 0

I’m trying to convert a complex Java applet to JavaScript. The applet does all sorts of magic with communicating on a TCP socket, which I will need to emulate in JavaScript. The TCP magic is itself quite complicated, so I’d rather do that later and get the graphical part of the applet working first. The communication over the TCP socket tells the applet what to draw, so depending on the data on the socket, the applet will read/write different values.

My current plan of attack is:

  • Pass request header to JavaScript as parameters (working) as well as needed data from socket depending on the request type
  • Parse header params/data sent in JS and create objects accordingly
  • Return value to calling Java function with an array of bytes to be written to the TCP socket

I’m stuck on the last part. If I return an array of bytes, how can I convert that to a byte[] or similar? Is the value passed back a proper Java array or is it some kind of object hash?

Java:

void callJavaScript(Applet app) {
    String[] params = {"blah", "cool"};

    JSObject win = JSObject.getWindow(app);
    Object ret = win.call("someFunction", params);

    // what is ret?
}

JavaScript:

function someFunction (blah, cool) {
    return [5, 7, 12, 2];
}

Note:

The complicated Java applet is multi-threaded, so just calling some function in the applet is non-trivial.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T11:10:46+00:00Added an answer on May 26, 2026 at 11:10 am

    Did just write a sample to check =)

    Test.java:

    import java.applet.Applet;
    import java.awt.*;
    import netscape.javascript.JSObject;
    
    public class Test extends Applet {
      public void init() {
        JSObject window = JSObject.getWindow(this); // this=applet
        String[] params = {"blah", "cool"};
        Object ret = window.call("testfunc", params);
        if (ret instanceof JSObject){
          JSObject jsret = (JSObject)ret;
          Object len = jsret.getMember("length");
          String val = "";
          if (len instanceof Number){
            val = "array: ";
            int n = ((Number)len).intValue();
            for (int i = 0; i < n; ++i){
                val += jsret.getSlot(i).toString() + " ";
            }
          } else{
            val = "no array: " + ret.toString();
          }
          String[] params2 = {val};
          window.call("alert", params2);
        } else{
          String[] params2 = {ret.toString()};
          window.call("alert", params2);
        }
      }
    }
    

    Test.html:

    <html>
      <head>
        <title> Test </title>
          <script language="JavaScript">
            function testfunc(a, b){
              return [1, 2];
            }
          </script>
        </head>
        <body>
          <applet code="Test.class" archive="." width="500" height="200"><param name="codebase_lookup" value="false"></applet>
        </body>
    </html>
    

    The conversions show in docstore.mik.ua/orelly/web/jscript/ch19_06.html seen to work(Figures 19.5 and 19.6). You can see in my code I checked len instanceof Number and not len instanceof Double because in my IE it returned an Integer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a text area in my form which accepts all possible characters from
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to loop through a bunch of documents I have to put
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Does anyone know how can I replace this 2 symbol below from the string
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.