CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 2000
    Location
    IL,U.S.A
    Posts
    33

    Applet to Applet communication

    Hi,
    I have a visual applet(applet2) containing a swing component(a JLabel
    ) and I have a non visual applet(applet1) which calls a javascript function. I am trying to create a bridge between the 2 applets.I want to display the result of the javascript function
    (applet2) in the label of applet1.
    I keep getting a JSException even before the applets are loaded.
    Can anybody help?

    Thanks in advance.


  2. #2
    Join Date
    Sep 1999
    Location
    Madurai , TamilNadu , INDIA
    Posts
    1,024

    Re: Applet to Applet communication


  3. #3
    Join Date
    Apr 2000
    Location
    IL,U.S.A
    Posts
    33

    Re: Applet to Applet communication

    Hi
    I did try the example you showed me. It works. But when I put any swing components on my applet1 and make applet2 access Javascript and use the java plugin.It doesn't work.Any Idea why?!
    Sushma


  4. #4
    Join Date
    Sep 1999
    Location
    Madurai , TamilNadu , INDIA
    Posts
    1,024

    Re: Applet to Applet communication


    Can you post your converted HTML file ? I have done this before ( with swing ). It worked
    for me.


  5. #5
    Join Date
    Apr 2000
    Location
    IL,U.S.A
    Posts
    33

    Re: Applet to Applet communication


    import java.awt.*;
    import java.applet.*;
    import javax.swing.*;
    import java.awt.event.*;
    import netscape.javascript.*;
    import netscape.javascript.JSException;

    public class SecondApplet extends Applet
    {

    JSObject win;
    String str;
    public void init()
    {
    str="This is SecondApplet talking";

    try
    {
    win = JSObject.getWindow(this);
    }
    catch(JSException e)
    { e=new JSException("win not found");}

    }


    public void getStr()
    {
    try
    {
    str="This is SecondApplet talking";
    str = (String)JSObject.getWindow(this).eval("text()");
    FirstApplet fa = (FirstApplet)getAppletContext().getApplet("First");
    if(fa != null)
    {
    fa.setLabel(str);
    }
    repaint();
    }
    catch(JSException jse)
    {
    jse = new JSException("Problem in Applet");

    }

    }

    public void paint(Graphics g)
    {
    getStr();

    g.drawString(str,500,200);

    }


    }



    I'm sorry I had to delete the comments in the HTML 'cause they're not being displayed on the actual message!


    appjava.html
    <HTML>
    <HEAD>
    <TITLE>
    APPLET TO APPLET FROM JAVASCRIPT
    </TITLE>
    <SCRIPT LANGUAGE = "JavaScript">
    function text()
    {
    return("HelloWorld!!!");
    }
    alert("hello");
    </SCRIPT>
    </HEAD>
    <BODY>


    </BODY>
    </HTML>



    "CONVERTED_APPLET"-->
    CONVERTER VERSION 1.0
    <OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
    WIDTH = 100 HEIGHT = 100 ID = "First" codebase="http://java.sun.com/products/plugin/....cab#Version=1,2,0,0">
    <PARAM NAME = CODE VALUE = "FirstApplet.class" >
    <PARAM NAME = ID VALUE = "First" >
    <PARAM NAME = "MAYSCRIPT" VALUE = "TRUE">

    <PARAM NAME="type" VALUE="application/x-java-applet;version=1.2">
    <COMMENT>
    <EMBED type="application/x-java-applet;version=1.2" java_CODE = "FirstApplet.class" ID = "First" WIDTH = 100 HEIGHT = 100 MAYSCRIPT=true pluginspage="http://java.sun.com/products/plugin/...n-install.html"><NOEMBED></COMMENT>

    </NOEMBED></EMBED>
    </OBJECT>

    have a comment here
    <APPLET CODE = "FirstApplet.class" WIDTH = 100 HEIGHT = 100 NAME = "First" >


    </APPLET>
    close comment
    "END_CONVERTED_APPLET"-->


    "CONVERTED_APPLET"
    CONVERTER VERSION 1.0
    <OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
    WIDTH = 10 HEIGHT = 10 ID = "Second" codebase="http://java.sun.com/products/plugin/....cab#Version=1,2,0,0">
    <PARAM NAME = CODE VALUE = "SecondApplet.class" >
    <PARAM NAME = ID VALUE = "Second" >
    <PARAM NAME = "MAYSCRIPT" VALUE = "TRUE">

    <PARAM NAME="type" VALUE="application/x-java-applet;version=1.2">
    <COMMENT>
    <EMBED type="application/x-java-applet;version=1.2" java_CODE = "SecondApplet.class" ID = "Second" WIDTH = 10 HEIGHT = 10 MAYSCRIPT=true pluginspage="http://java.sun.com/products/plugin/...n-install.html"><NOEMBED></COMMENT>

    </NOEMBED></EMBED>
    </OBJECT>

    comment
    <APPLET CODE = "SecondApplet.class" WIDTH = 10 HEIGHT = 10 NAME = "Second" >


    </APPLET>
    close comment
    "END_CONVERTED_APPLET"


  6. #6
    Join Date
    Sep 1999
    Location
    Madurai , TamilNadu , INDIA
    Posts
    1,024

    Re: Applet to Applet communication


    In your HTML file , you are missing "name" value in both the Object tag.


    <PARAM NAME="name" value="First"> // for "FirstApplet"


    <PARAM NAME="name" value="Second"> // for "Second Applet"

    Both are missing in your HTML File.

    Ex :
    <OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
    WIDTH = 100 HEIGHT = 100 ID = "First" codebase="http://java.sun.com/products/plugin/....cab#Version=1,2,0,0">
    <PARAM NAME = CODE VALUE = "FirstApplet.class" >
    <PARAM NAME = ID VALUE = "First" >
    <PARAM NAME = "MAYSCRIPT" VALUE = "TRUE">
    <PARAM NAME ="name" VALUE = "First">


    Sorry , I dont know about NS Option. Try the same thing in EMBED tag.



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured