Static variables accessed by applets not static when applet added from JS?!
Using static methods to communicate between applets on different frames is a fairly common practice. Recently I wanted to do this with applets that were dynamically added via JavaScript. I found that applets added in such a way do not refer to the same static variables and methods that other applets do!
I have a copy of an applet on page which calls methods that reside in an applet on another frame using a central communicationregister class which stores static references to other applets. When I dynamically create a new copy of this applet using JS the newly created applet *cannot* access these same variables.
Relevant code from communicationregister class:
privatestatic ACFControlApplet controlApplet;
publicstatic ACFControlApplet getControlApplet(){
return controlApplet;
}
Sample code from dependant applet:
publicvoid mouseClicked(MouseEvent evt){
ACFControlApplet control = CommManager.getControlApplet();
if (control !=null)
{
System.out.println("Control not null.");
}
else{
System.out.println("Control null.");
}
}
This prints "Control not null." when called from applet that resides on page but when a new copy of this applet is added to the page dynamically it prints "Control null."
Finally sample JS code to add applet to page (it's in a table cell):
var cell = newRow.insertCell(1);
var applet = document.createElement('object');
applet.code ='dependantapplet.class';
cell.appendChild(applet);
The applet loads and displays fine, responds to mouse clicks, etc, it just doesn't have access to the same static variables which seems to contradict the definition of static.

