This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Applets and the fly likes Problem with inter-applet communication Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "Problem with inter-applet communication" Watch "Problem with inter-applet communication" New topic

Problem with inter-applet communication

Velika Srbija
Ranch Hand

Joined: Jan 15, 2002
Posts: 172
I have inter-applet communication between two applets at my JSP page.
It work's OK, but when I put them into separate JAR archives they get loaded and started correctly at my JSP page, but they does't see each other (no inter-applet communication).
e.g., I got the following error:

Both applets contains updateOtherApplets method and it is very simillar.
For example, here is code excerpt from Applet2, so you can see how it is implemented:

And there is code excerpt from my JSP page:

Why there is no inter-applet communication between applets when I put them into JAR archives?
[ October 09, 2005: Message edited by: Velika Srbija ]
Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 685
Do the applets communicate if they are referenced in a static HTML page?
IE Leave off the jsp until you get the correct HTML coding.
Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 685
Here is my test case for this problem. The instanceof test and ClassCast fails but the getClass() shows the same named class?
To get the programs to work I overrode an existing method (getForeground() in the applet to demonstrate that the applets can communicate.

How do you get them to work via casting?
I put the "Master" class definition in the Bullet jar. The Bullet class needs the definition to be able to do the cast.

******* The HTML for testing the above applets *******************************
<HTML><HEAD><TITLE>Test inter applet commuication</TITLE></HEAD>
<applet name="Master" code=Testing.AppletCommMain archive=AppletCommMain.jar width=200 height=100>

<applet name="Bullet1" code=Testing.AppletCommBullet archive=AppletCommBullet.jar width=50 height=50>

<applet name="Bullet2" code=Testing.AppletCommBullet archive=AppletCommBullet.jar width=50 height=50>

************ The batch file that creates the jar files: **********************
@REM Make jar files for testing Applet Communications
cd ..
jar -cf Testing\AppletCommMain.jar Testing\AppletCommMain.class
jar -cf Testing\AppletCommBullet.jar Testing\AppletCommBullet.class Testing\AppletCommMain.class
Velika Srbija
Ranch Hand

Joined: Jan 15, 2002
Posts: 172
Thank YOU very much!
Now, it is working the right way. I put all applets, that are referenced from the same JSP page, into single JAR archive and now it works without problems.
Though, I have some if statements in my JSP page, so there are situations when I don't need all applets loaded at once, but it doesn't mind to have all of them always available.
Thanks once again!

Norm Radder, if you don't mind, take a look at one of my older questions: Problem with drawing styled (attributed) text
Do you have any idea?
I agree. Here's the link:
subject: Problem with inter-applet communication