Solved

calling applet in separate frame

Posted on 1997-12-18
9
188 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 

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
 

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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

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…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
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…
Suggested Courses

739 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