Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to call another applet

 
syed baber owais
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I want to know that how to call one applet from another applet which is already running.I want the exact code from which i can call another applet.say that i want to call Applet2 from Applet1 already running.I need it desperately.Plz can anybody hep with this.

thanks.
 
Shalini Chandel
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can follow the steps given below:

Since you need both the applet to communicate, you need to have both applets in the same page. But the problem in this case is that both the applets will load independently of each other. You can control the behaviour of the other applet from the first one. But your requirement is of loading the another applet from the first one.

You can have two frames in a page . In one frame there will be your first applet which will load automatically when the page is loaded. And the other frame will contain a blank page. Now on certain event in the first applet you can use "this.showDocument("URL") " to make a call to another applet which you want to load. Give the target parameter as the other frame. (You will have to give the name of the other frame) Now when these two applets are loaded they can exchange data in their life time.
 
Vinayak Sharma
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the code: But assumption is that both the applets are running in the same browser. Applet Security doesn't allow applets on diff browsers to communicate

/*This code is in Applet1, from where you get reference to Applet2 and call any of its methods you want or access any of the public variables you want to access*/

Enumeration enumApplets = getAppletContext().getApplets();

Applet applet;
while (enumApplets.hasMoreElements())
{
applet = (Applet)enumApplets.nextElement();

if ((applet.getClass().toString()).equalsIgnoreCase("class test.Applet2"))
{
if (applet instanceof test.Applet2)
{
Applet2 app2 = (test.Applet2)applet;
// Call whatever methods u want to call
}
}
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic