• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to call another applet

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
}
}
}
reply
    Bookmark Topic Watch Topic
  • New Topic