Click to See Complete Forum and Search --> : Applet to Applet communication
sush
May 8th, 2000, 11:33 AM
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.
poochi
May 8th, 2000, 05:22 PM
Look at this site : http://codeguru.developer.com/java/articles/376.shtml
sush
May 9th, 2000, 08:48 AM
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
poochi
May 9th, 2000, 10:54 AM
Can you post your converted HTML file ? I have done this before ( with swing ). It worked
for me.
sush
May 9th, 2000, 11:40 AM
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/1.2/jinstall-12-win32.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/1.2/plugin-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/1.2/jinstall-12-win32.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/1.2/plugin-install.html"><NOEMBED></COMMENT>
</NOEMBED></EMBED>
</OBJECT>
comment
<APPLET CODE = "SecondApplet.class" WIDTH = 10 HEIGHT = 10 NAME = "Second" >
</APPLET>
close comment
"END_CONVERTED_APPLET"
poochi
May 9th, 2000, 03:32 PM
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/1.2/jinstall-12-win32.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.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.