?
Solved

calling applet in separate frame

Posted on 1997-12-18
9
Medium Priority
?
191 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
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
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 will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month12 days, 13 hours left to enroll

777 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