Closed Bug 88150 Opened 23 years ago Closed 23 years ago

Applet cant call JavaScript function calling applet method in applet start method

Categories

(Core Graveyard :: Java: OJI, defect)

x86
Other
defect
Not set
normal

Tracking

(Not tracked)

VERIFIED FIXED

People

(Reporter: co, Assigned: xiaobin.lu)

Details

Applet cant call JavaScript function calling applet method in applet start
method I have make a very simple applet that call JavaScript function in the
document. That function in turn calls a method of the applet to set the label of
a button of the applet. It is only working halfway through, the JavaScript
function is being called and execute. But it hangs when calling back the applet
method.

<HTML>
<HEAD>
<TITLE>J2JS2J</TITLE>
<SCRIPT><!--

function myJ2JS2JCallback(s){
	alert("Half-way through!");
	document.myApplet.getButton().setLabel(s);
	document.myApplet.doLayout();
	document.myApplet.validate();
}
//-->
</SCRIPT>
</HEAD>
<BODY>
<H1>J2JS2J</H1>
<p>
<A HREF=J2JS2J.java>Source code for J2JS2J</A>
<p>
<APPLET name="myApplet" CODE="J2JS2J" CODEBASE="file:///C:/dev" WIDTH="300"
HEIGHT="150" MAYSCRIPT>
</APPLET>
</BODY>
</HTML>



import java.applet.*;
import java.awt.*;
/**
 * Creation date: (27/06/2001 21:46:52)
 * @author: 
 */
public class J2JS2J extends Applet implements java.awt.event.ActionListener{
	Button button = new Button("Hello!");
/**
 * @see java.awt.event.ActionListener
 */
public void actionPerformed(java.awt.event.ActionEvent e) {
	// insert any code to be run when the applet starts here
	try {
		netscape.javascript.JSObject obj = netscape.javascript.JSObject.getWindow(this);
		obj.eval("myJ2JS2JCallback('Lets go Ed, you are my hero!')");
	} catch (Throwable ex) {
		ex.printStackTrace();
	}
}
/**
 * Returns information about this applet.
 * @return a string of information about this applet
 */
public String getAppletInfo() {
	return "J2JS2J\n" + 
		"\n" + 
		"Creation date: (27/06/2001 21:46:52)\n" + 
		"@author: \n" + 
		"";
}
/**
 * Creation date: (27/06/2001 21:48:55)
 * @return java.awt.Button
 */
public java.awt.Button getButton() {
	return button;
}
/**
 * Initializes the applet.
 * 
 * @see #start
 * @see #stop
 * @see #destroy
 */
public void init() {
	super.init();

	// insert code to initialize the applet here
	setLayout(new FlowLayout());
	add(button);
	button.addActionListener(this);
}
/**
 * Called to start the applet. You never need to call this method
 * directly, it is called when the applet's document is visited.
 * @see #init
 * @see #stop
 * @see #destroy
 */
public void start() {
	super.start();

}
/**
 * Called to stop the applet. It is called when the applet's document is
 * no longer on the screen. It is guaranteed to be called before destroy()
 * is called. You never need to call this method directly.
 * @see #init
 * @see #start
 * @see #destroy
 */
public void stop() {
	super.stop();

	// insert any code to be run when the applet is stopped here
}
}
import java.applet.*;
import java.awt.*;
/**
 * Creation date: (27/06/2001 21:46:52)
 * @author: 
 */
public class J2JS2J extends Applet implements java.awt.event.ActionListener{
	Button button = new Button("Hello!");
/**
 * @see java.awt.event.ActionListener
 */
public void actionPerformed(java.awt.event.ActionEvent e) {
	// insert any code to be run when the applet starts here
	try {
		netscape.javascript.JSObject obj = netscape.javascript.JSObject.getWindow(this);
		obj.eval("myJ2JS2JCallback('Lets go Ed, you are my hero!')");
	} catch (Throwable ex) {
		ex.printStackTrace();
	}
}
/**
 * Returns information about this applet.
 * @return a string of information about this applet
 */
public String getAppletInfo() {
	return "J2JS2J\n" + 
		"\n" + 
		"Creation date: (27/06/2001 21:46:52)\n" + 
		"@author: \n" + 
		"";
}
/**
 * Creation date: (27/06/2001 21:48:55)
 * @return java.awt.Button
 */
public java.awt.Button getButton() {
	return button;
}
/**
 * Initializes the applet.
 * 
 * @see #start
 * @see #stop
 * @see #destroy
 */
public void init() {
	super.init();

	// insert code to initialize the applet here
	setLayout(new FlowLayout());
	add(button);
	button.addActionListener(this);
}
/**
 * Called to start the applet. You never need to call this method
 * directly, it is called when the applet's document is visited.
 * @see #init
 * @see #stop
 * @see #destroy
 */
public void start() {
	super.start();

}
/**
 * Called to stop the applet. It is called when the applet's document is
 * no longer on the screen. It is guaranteed to be called before destroy()
 * is called. You never need to call this method directly.
 * @see #init
 * @see #start
 * @see #destroy
 */
public void stop() {
	super.stop();

	// insert any code to be run when the applet is stopped here
}
}
import java.applet.*;
import java.awt.*;
/**
 * Creation date: (27/06/2001 21:46:52)
 * @author: 
 */
public class J2JS2J extends Applet implements java.awt.event.ActionListener{
	Button button = new Button("Hello!");
/**
 * @see java.awt.event.ActionListener
 */
public void actionPerformed(java.awt.event.ActionEvent e) {
	// insert any code to be run when the applet starts here
	try {
		netscape.javascript.JSObject obj = netscape.javascript.JSObject.getWindow(this);
		obj.eval("myJ2JS2JCallback('Lets go Ed, you are my hero!')");
	} catch (Throwable ex) {
		ex.printStackTrace();
	}
}
/**
 * Returns information about this applet.
 * @return a string of information about this applet
 */
public String getAppletInfo() {
	return "J2JS2J\n" + 
		"\n" + 
		"Creation date: (27/06/2001 21:46:52)\n" + 
		"@author: \n" + 
		"";
}
/**
 * Creation date: (27/06/2001 21:48:55)
 * @return java.awt.Button
 */
public java.awt.Button getButton() {
	return button;
}
/**
 * Initializes the applet.
 * 
 * @see #start
 * @see #stop
 * @see #destroy
 */
public void init() {
	super.init();

	// insert code to initialize the applet here
	setLayout(new FlowLayout());
	add(button);
	button.addActionListener(this);
}
/**
 * Called to start the applet. You never need to call this method
 * directly, it is called when the applet's document is visited.
 * @see #init
 * @see #stop
 * @see #destroy
 */
public void start() {
	super.start();

}
/**
 * Called to stop the applet. It is called when the applet's document is
 * no longer on the screen. It is guaranteed to be called before destroy()
 * is called. You never need to call this method directly.
 * @see #init
 * @see #start
 * @see #destroy
 */
public void stop() {
	super.stop();

	// insert any code to be run when the applet is stopped here
}
}
I think you have to do what you're doing in your init() method.  Xiaobin, can 
you please comment?
Assignee: edburns → xiaobin.lu
Summary: Applet cant call JavaScript function calling applet method in applet start method → Applet cant call JavaScript function calling applet method in applet start method
Please test it. It works fine with nightly build.
Fixed in trunk with JRE1.3.1.
Status: UNCONFIRMED → RESOLVED
Closed: 23 years ago
Resolution: --- → FIXED
qa->pmac
QA Contact: shrir → pmac
Verified on the commercial trunk (2001-09-06-05-trunk)
Status: RESOLVED → VERIFIED
Product: Core → Core Graveyard
You need to log in before you can comment on or make changes to this bug.