Solved

calling applet in separate frame

Posted on 1997-12-18
9
185 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
ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java Jpanels and Jframe 8 33
object oriented programming comparison 5 72
eclipse apache tomcat admin console 52 97
runtime exception 2 30
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
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 learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

832 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