Link to home
Start Free TrialLog in
Avatar of wchiang
wchiang

asked on

passing parameters between applets

how can I pass parameters between applets?
Avatar of jpk041897
jpk041897

1) First make sure that you have used the NAME attribute and assigned a diffren name for all applets in the APPLET tag of your HTML code.

2) Make a call similar to:

AplletContext a = getAppletContext(string AppletName);

note this method only works on Netscape.

If you want this to run on any browser, you wiill need to use JavaScript and define some methods that will allow you to get/send members between the applets using the Javascript as a bridge.
jpk, I think that there is a better way to do that.
wchiang, what you need to do is to define a class that has a static variable. Through that variable all the applets that are running on the same JVM (on the same browser), can communicate. This method will work for both Netscape and IE. If you need more information, don't hesitate to ask
:-)

G.
I support gadio's sugestion, because Javascript to Java (using the applet NAME) is browser independent, however, Java to Javascript is not. The applet NAME is a Javascript artifact and is aproperty of the document, as the applet is an object embeded in it. So, between applets, better use static variables.

Cheers,
  Nik
Gadio an DIakov are correct. I stand corrected.

Please reject this answer and give the points to Gadio.

cheers :-)
Avatar of wchiang

ASKER

Gadio,
Can you give an example including the static variable class?
Thanks,
wchiang
Avatar of wchiang

ASKER

Gadio,
were you waiting for an increase in points? Is 100 enough?
Thanks,
wchiang
I can give an example, if gadio is away. Tell me...

Cheers,
  Nik
Avatar of wchiang

ASKER

diakov,
I assume Gadio is away somewhere so it'd be great if you can give an example.
Thanks,
wchiang
wschiang,

You can find a good article on inter applet communication (which I promptly forgot about ) at:

http://www.javaworld.com/javaworld/jw-03-1996/jw-03-javadev.html

for code.

Gadio should still get the points since he spotted my mistake, but the article should get you rolling while gadio replies.
1. gadio gets the points.
2. a simple example to keep wchiang rolling:

Assume you have applet1 and applet2 classes. Also, assume there is a class called StaticWrapper:

class StaticWrapper
{
  public static Holder ref = null;

  public static Holder getRef()
  { return ref; }
  public static void setRef(Holder h)
  { ref = h; }
}

interface Holder
{
}

//concrete holder Value for setting/getting ints
class Value implements Holder
{
  private int value = 0;
  public synchronized int getValue()
  { return value; }
  public synchronized void setValue(int v)
  { value = v; }
}

You have to implement your own Value class for the concrete value you're going to share between the two applets.

In applet1 (applet2) methods you can call StaticWrapper.getRef() or StaticWrapper.setRef() to get/set an object of type Value and obtain/store whatever int value (in an independent for the Wrapper way) you want. This way the Holder (with specialization Value) can be accessed by both applet1 and applet2 if they share one Java machine.

Cheers,
  Nik
Avatar of wchiang

ASKER

gadio,
please post your answer so I can give you the points.

diakov/jpk,
Thanks!
ASKER CERTIFIED SOLUTION
Avatar of gadio
gadio

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I can't be more specific at this moment: somebody told me that there can be problems with some browser when the applets are with different codebases. Ideally, different codebases should mean separate context environments.

Make sure, your two applets are with the same codebase otherwise it can be a problem to share static references.

Cheers,
  Nik
This question was awarded, but never cleared due to the JSP-500 errors of that time.  It was "stuck" against userID -1 versus the intended expert whom you awarded.  This corrects the problem and the expert will now receive these points; points verified.

Please click on your Member Profile and select "View Question History" to navigate through any open or locked questions you may have to update and finalize them.  Or if you are an EE Pro user, click the link below to select open items for your Member ID using Power Search:
https://www.experts-exchange.com/jsp/qPowerSearch.jsp.

This is the Community Support link, if help is needed, along with the link to All Topics which reflects many TAs recently added.

https://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
https://www.experts-exchange.com/jsp/zonesAll.jsp
 
Thank you,
Moondancer
Moderator @ Experts Exchange