Solved

calling applet in separate frame

Posted on 1997-12-18
9
182 Views
Last Modified: 2012-06-27
I have 2 applets in 2 separate frames. How would one applet call another?
0
Comment
Question by:markoj
  • 4
  • 3
  • 2
9 Comments
 
LVL 6

Accepted Solution

by:
jpk041897 earned 150 total points
ID: 1231704
There are several techniques you can use:

1)

Applet friend = getAppletContext().getApplet("Friend");

where the Friend applet is defined with <applet code = "Some.class" width=20 height=20 name="Friend">

and then use friend.method() or friend.member to estabish communication.

2)

You could use static variablesand methods which are defined and used in both classes

3)

You could use a server app to tranfer data between the applets (If they were not loaded by the same page)

or

4)

You could use threads and the ThreadGroup hierarchy (mainly for control purposes).


If you want to see documentation and samples on all these techniques, go to http://www.mcp.com and read Chapter 1 of the on-line book: Tricks of Java Programming Gurus.
0
 

Author Comment

by:markoj
ID: 1231705
Hm. I tried 1st solution, but it doesn't seem to work. If the applets are in the same frame, then it works. If I put them in
seprate ones it stops working.
0
 
LVL 6

Expert Comment

by:jpk041897
ID: 1231706
Well, that seems to leave you with static variables and methods or networks as alternatives.

Since the network solutions imply either defining your own protocol (over http tunneling) in order to exchange data, as well as establishing a polling mechanism on the server applet(s), its realy only practical for comunicating applets across networks or broser (diferen browser or browser instances) boundries.

The referance I gave you has a verry complete example on using a common class for inter applet communication, including applet registration into the shared service.

As a final alternative, you could also use RMI or CORBA establishing localhost calls. But this would probably be an overkill.
0
 

Expert Comment

by:priyam
ID: 1231707
I've done this sort of thing before - one applet in a frame , calling methods of  a 2nd  applet in another frame  , and vice-versa .
Lemme know if you  want more info .
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:markoj
ID: 1231708
I'd be thankful.
0
 

Author Comment

by:markoj
ID: 1231709
To jpk: I'll grade your answer as soon as I get code from priyam.
0
 
LVL 6

Expert Comment

by:jpk041897
ID: 1231710
markoj,

If the code from pryam works better than my answer, F my answer an give the points to pryam.
0
 

Expert Comment

by:priyam
ID: 1231711
Hi ! I'm not doing this for points , so  it doesn't matter who you grade  (I didn't realize this question was locked - sorry jpk )
Anyway , my solution is similar to what jpk suggested .
What I've done is , used a common class with static variables , which this class uses to reference the other 2 applets in the separate frames .
Consider that appA ,appB are the 2 aplets in separate frames , and apC is the common class .
 The code in appC  is something like this ::

static appA refA ;
static appB refB ;

public void  regA(appA param)
{
refA = param ;
}
public void regB(appB param)
{
refB = param ;
}

public void  callA()
{
refA.methodA() ;
}
public void callB()
{
refB.methodB() ;
}

When appA and appB are initialised , the register themselves with appC by passing  their references as parameters to the corresponding appC methods :
----------------------
for appA :

appC refAC ;
In its init() or start() method :
refAC = new appC() ;
refAC.regA(this) ;
-------------------------------
for appB :

appC refBC ;

In its init() or start() method :
refBC = new appC() ;
refBC.regB(this) ;
---------------------------------
This way appC now has reference to both the apps .
Now if appA wants to call a public method of appC (say , methodB() ) ,
one way it could do this is by indirectly calling a public method of
appC ( callB()), which in turn  calls the public method of appB
in its method  , for example , the code in appA would be :
 refAC.callB() ;

Similarly . for appB to call appA :
refBC.callA() ;


I hope this is not too confusing -  I'm sorry if it is .
I'm unable to send you actual code at the moment - am a little tied up .
Don't worry about the grades and stuff  - it's inconsequential  - besides , jpk deserves it more than me , since I'm probably suggesting the same thing he did.

Regards,
Priya






0
 

Author Comment

by:markoj
ID: 1231712
This is exactly what I did, following jpk's instructions. So I'll grade his answer. But thank you anyway. I'm sure your answer will help others - that won't have to exepriment as much as I had to.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This video teaches viewers about errors in exception handling.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now