Copyright (c) SEMM NL All rights reserved.
Author : Paul Hamaker. Part of JavaLessons.com

The point.

Applets that are in the same HTML document, can call each other's methods, as shown by these two applets.

The methods have to be public.

To be able to find one another, they must have names. This is taken care of in the HTML APPLET tags.

ApComdue's performRequest method is called in ApComuno's actionPerformed method .

Prior to this, applet due must have been found.

We get a reference to an object that most of the time represents the browser by telling the applet to get its context, java.applet.AppletContext .

Then the context is asked to find applet due .

If it has NOT been found, we leave the method .

If the applet has been found, we check if the Applet reference points to an instance of ApComdue. ( ! = NOT )

We cast apl to our class type ,....

so we can call ApComdue's performRequest method .

We CANNOT do this with apl, because that's a reference to Applet, which obviously does NOT contain our method performRequest.

ApComdue, in a similar way, calls uno's performRequest method.

The method doesn't have to be void, it can return anything that is Serializable, as most core classes are. In addition to that you can pass Serializable arguments.

=======

NOTES

=======

It is said that a more flexible solution would be to use static data as a means to communicate, but there's no guarantee that this works in every context.

.