JAVA and JAVAScript interCommunication

hello,

i have a problem as follows:::

there is an HTML file having two buttons.

clicking first button opens an applet in package 'comcopy' using innerHTML , which opens a frame containg a button titled say 'open_Another_Applet_in_Same_HTML'.

when i click on this frame 's button, i need to open another applet

mentioned in the code below in the same HTML page using the same innerHTML technique and using the same applet code pattern as used for first one, but just with different class Name this time obviously

the problem is that it opens the first one but shows 'Applet loading failed message' while opening the second applet .

1)the code for the HTML is as follows::::::

<html>

<head>

<script language="javascript" >

function openSenderApplet(){

var str = new String('<APPLET NAME="sender" id="sender" CODE = "comcopy.SenderApplet3.class"');

str += ' width="100" height="100" ALIGN="LEFT" ARCHIVE = "appletcom3.jar" codebase="."> ';

str+='<PARAM NAME="MAYSCRIPT" VALUE="true">';

str+='<PARAM NAME="scriptable" VALUE="true">';

str+='</APPLET>';

document.getElementById('bod').innerHTML += str;

}

function openReceiverApplet(){

var str = new String('><APPLET NAME="receiver" id="receiver" CODE = "comcopy.ReceiveApplet3.class"');

str += ' width="100" height="100" ALIGN="right" ARCHIVE = "appletcom3.jar" codebase="."> ';

str+='</APPLET>';

document.getElementById('bod').innerHTML += str;

}

></script>

</head>

<body id='bod'>

<INPUT TYPE="button" NAME="senders" value="senders" onclick="openSenderApplet();">

<INPUT TYPE="button" NAME="receivers" value="receivers" onclick="openReceiverApplet();">

</body>

</html>

2) the code for the senderApplet is as follows:::::

/*********************************************************************

* **************************************************************************\ * *

* MainWindow.java * * TODO Write descrition for MainWindow.java. * *

* Copyright (c) 2001-2005 Quark, Inc. * All Rights Reserved * *

* Author: * Deepak Gupta * * $Header: $ * \

********************************************************************/

package comcopy;

import java.awt.BorderLayout;

import java.awt.Color;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.WindowAdapter;

import java.awt.event.WindowEvent;

import java.util.Enumeration;

import javax.swing.JApplet;

import javax.swing.JButton;

import javax.swing.JFrame;

import sun.plugin.AppletViewer;

import sun.plugin.dom.html.HTMLCollection;

import netscape.javascript.JSException;

import netscape.javascript.JSObject;

import netscape.javascript.JSObject;

/**

* TODO Write descrition for MainWindow

*

* @since QWE 4.0

*

* @author Deepak Gupta

*/

@SuppressWarnings("serial")

public class SenderApplet3 extends JApplet {

private JSObject window;

private JSObject document;

private JSObject body;

private JFrame workflowDesigner = null; // @jve:decl-index=0:visual-constraint="10,30"

private JButton senderButton = null; // @jve:decl-index=0:visual-constraint="614,30"

private ReceiveApplet3 recApplet = null;

/**

* This is the default constructor

*/

public SenderApplet3() {

super();

}

/**

* This method initializes workflowTemplateDesigner

*

* @return com.netmidas.workflow.designer.client.ProcessDesigner

*/

private JFrame getFrame1() {

if (workflowDesigner == null) {

workflowDesigner = new JFrame();

workflowDesigner.setVisible(true);

workflowDesigner.setSize(400, 400);

workflowDesigner.setCursor(new java.awt.Cursor(

java.awt.Cursor.DEFAULT_CURSOR));

workflowDesigner.setTitle("senderFrame");

workflowDesigner.setLayout(new BorderLayout());

workflowDesigner.addWindowListener(new WindowAdapter() {

public void windowClosing(WindowEvent e) {

workflowDesigner = null;

}

});

workflowDesigner.add(getSenderButton(), BorderLayout.NORTH);

}

return workflowDesigner;

}

public void init() {

super.init();

this.setVisible(false);

this.hide();

getFrame1();

}

public void showFrame1() {

getFrame1();

}

/**

* This method initializes senderButton

*

* @return javax.swing.JButton

*/

public JButton getSenderButton() {

if (senderButton == null) {

senderButton = new JButton();

senderButton.setText("senderbutton");

senderButton.addActionListener(new ActionListener() {

// click on a button in a frame in an applet to take

// action on a frame in other applet

public void actionPerformed(ActionEvent e) {

System.out

.println("SenderApplet3::::::getSenderButton().addActionListener called");

recApplet = new ReceiveApplet3();

recApplet.setSize(300, 300);

recApplet.setVisible(true);

recApplet.getJTextField().setText(

"text set on buttton click in sender");

//

try {

window = JSObject.getWindow(SenderApplet3.this);

System.out.println("initsssss()\twindow=" + window);

window.call("openReceiverApplet", null);

Enumeration e1 = SenderApplet3.this.getAppletContext()

.getApplets();

int i = 0;

while (e1.hasMoreElements()) {

e1.nextElement();

i++;

}

System.out.println("i is::" + i);

Enumeration e2 = SenderApplet3.this.getAppletContext()

.getApplets();

int ii = 0;

while (e1.hasMoreElements()) {

e1.nextElement();

ii++;

}

System.out.println("ii is::" + ii);

}

catch (JSException ex) {

// We couldn't get reference to either object

ex.printStackTrace();

}

//

}

});

}

return senderButton;

}

/**

* TODO Write description for getR.

*

* @return Returns the r.

*

* @author prakumar

*

* @since QWE 4.0

*/

public ReceiveApplet3 getRecApplet() {

return recApplet;

}

/**

* TODO Write description for setR.

*

* @param r The r to set.

*

* @author prakumar

*

* @since QWE 4.0

*/

public void setRecApplet(ReceiveApplet3 r) {

this.recApplet = r;

}

}

/*********************************************************************

* **************************************************************************\ * *

* $Log: $ * \

********************************************************************/

ReceiveAppler class is also in the same package.

please help .

Thanx in anticipation,

[7200 byte] By [Sonu.Aroraa] at [2007-10-2 6:02:15]
# 1
> innerHTML += str;I don't do JavaScript much, but, may be:innerHTML = str;
hiwaa at 2007-7-16 13:02:36 > top of Java-index,Desktop,Core GUI APIs...