Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

How to call another applet

 
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.
 
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.
 
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
}
}
}
 
Space seems cool in the movies, but once you get out there, it is super boring. Now for a fascinating tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic