News:

GinGly.com - Used by 85,000 Members - SMS Backed up 7,35,000 - Contacts Stored  28,850 !!

Main Menu

Sending Messages to Other Applets

Started by sukishan, Jul 15, 2009, 03:13 PM

Previous topic - Next topic

sukishan

Sending Messages to Other Applets
Applets can find other applets and send messages to them, with the following security restrictions:

Many browsers require that the applets originate from the same server.
Many browsers further require that the applets originate from the same directory on the server (the same code base).
The Java API requires that the applets be running on the same page, in the same browser window.

An applet can find another applet either by looking it up by name (using the AppletContext getApplet method) or by finding all the applets on the page (using the AppletContext getApplets method). Both methods, if successful, give the caller one or more Applet objects. Once the caller finds an Applet object, the caller can invoke methods on the object.

Finding an Applet by Name: The getApplet Method
The getApplet method looks through all of the applets on the current page to see if one of them has the specified name. If so, getApplet returns the applet's Applet object.

By default, an applet has no name. For an applet to have a name, one must be specified in the HTML code that adds the applet to a page. You can specify an applet's name in two ways:

By specifying a NAME attribute within the applet's <APPLET> tag. For example:
<APPLET CODEBASE=example/ CODE=Sender.class
    WIDTH=450
    HEIGHT=200
    NAME="buddy">
. . .
</APPLET>

By specifying a NAME parameter with a <PARAM> tag. For example:
<APPLET CODEBASE=example/ CODE=Receiver.class
    WIDTH=450
    HEIGHT=50>
<PARAM NAME="name" value="old pal">
. . .
</APPLET>
A good beginning makes a good ending