[5589] in java-interest

home help back first fref pref prev next nref lref last post

Re: Inter-applet Communication

daemon@ATHENA.MIT.EDU (guy.elliott)
Sun Feb 18 17:40:23 1996

To: bruno souza - sun do brasil <bruno.souza@Brazil.Sun.COM>
Cc: jkap <jkap@jade.org>, java-interest <java-interest@java.Eng.Sun.COM>
From: "guy.elliott" <guy.elliott@ac.com>
Date: 15 Feb 96  9:59:24 

In addition to this I am interested to know if anyone knows if applets can 
communicate across frames.  Are applets in different frames considered to be in 
the same AppletContext, I know this would be pretty easy to test, and I will 
sometime soon.  I just wanted to know if anyone had tried already and could 
save me some work.

TIA,

Guy
___________________________________________________________________________________________________________________________________________________________________________________________________________________
To: jkap @ jade.org  @ internet, java-interest @ java.eng.sun.com  @ internet
cc:  (bcc: Guy Elliott)
From: Bruno.Souza @ Brazil.Sun.COM (Bruno Souza - Sun do Brasil) @ internet
Date: 02/12/96 07:42 AM
Subject: Re: Inter-applet Communication
___________________________________________________________________________________________________________________________________________________________________________________________________________________
> 
> Can anyone provide (or point me toward) any information about inter-applet 
communication, specifically in a multi-page environment?
> 

Lot's of people has been asking this, so let me try to sumarize what
I've learned in the last weeks. (Someone that knows better, *please*
correct any mistake!!! :-)

Applets can comunicate with each other through method calling if the
applets have been loaded in the same page. I had no success so far to
make applets from different pages to comunicate (I haven't tried too
much either, since I believe it's not possible :-)

The usual way to applet1 call a method of applet2 is to applet1 grab a
handle to applet2 with AppletContext.getApplet(), do a cast to applet2
and then call it's method:

 Applet2 ap2 = (Applet2) getAppletContext().getApplet("Name_in_HTML_tag");

where "Name_in_HTML_tag" is the argument in the "name" tag on the
applet2 call ont the HTML file.

This should work, and it acctually does under appletviewer (I've tryed
both the Solaris & Windows95 version) but it *does not* work under
netscape (I've tried versions b5, b6 and final). It seems that netscape
can do AppletContext.getApplets(), but not AppletContext.getApplet().
So, the workaround that <jmarin@superlink.com> send me (and it works
beutiffuly Marin, thanks!) is to make an enumeration with
AppletContext.getApplets(), and then look for the applet that you
want:

 // get the applet context
 m_ac = getAppletContext();

 // get all applets in m_ac
 Enumeration en = m_ac.getApplets();

        for (; en.hasMoreElements() ;) 
        {
  Object o = en.nextElement();
  String name = o.getClass().getName();

  // if it is the applet I'm looking for
  if(name.equals("Applet2"))
  {
   // make a cast
   (Applet2) o;
  }
        }

 // if I got the reference to the applet
 if (o != null)
 {
  // call the method
  o.Applet2_Method(Method_Arguments);
 }

With this you don't need to use the "name" parameter in the applet tag,
because the name that you get from AppletContext.getApplets() is the
name of the class.

Hope this is not too much confusing :-) If someone does know how to
make applets that were loaded in diferent pages to comunicate in any
way (besides going back to the server to get their common info), I
would like to hear!!



Bruno.
___________________________________________________________
Bruno Peres Ferreira de Souza              Sun Microsystems
                       Bruno.Souza@Brazil.Sun.COM
                                     


> Thanks,
> -Jonathan
> 
> 
--------------------------------------------------------------------------------
> Jonathan Kaplan
> jade.org:The Java(tm) Developers Organization
> 500 Bloomfield Ave
> Verona, NJ 07044       (201) 239-7500 x264
> http://www.jade.org
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com


-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com

-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post