Solved

calling applet in separate frame

Posted on 1997-12-18
9
180 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:markoj
Comment Utility
I'd be thankful.
0
 

Author Comment

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

Expert Comment

by:jpk041897
Comment Utility
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
Comment Utility
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
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

743 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

11 Experts available now in Live!

Get 1:1 Help Now