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

VERIFIED FIXED

Status

VERIFIED FIXED
18 years ago
9 years ago

People

(Reporter: co, Assigned: xiaobin.lu)

Tracking

Trunk
x86
Other

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

18 years ago
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
}
}

Comment 1

18 years ago
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
(Assignee)

Comment 2

18 years ago
Please test it. It works fine with nightly build.
(Assignee)

Comment 3

18 years ago
Fixed in trunk with JRE1.3.1.
Status: UNCONFIRMED → RESOLVED
Last Resolved: 18 years ago
Resolution: --- → FIXED

Comment 4

18 years ago
qa->pmac
QA Contact: shrir → pmac

Comment 5

18 years ago
Verified on the commercial trunk (2001-09-06-05-trunk)
Status: RESOLVED → VERIFIED

Updated

9 years ago
Component: Java: OJI → Java: OJI
Product: Core → Core Graveyard
You need to log in before you can comment on or make changes to this bug.