Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

passing parameters between applets

Posted on 1999-06-25
14
Medium Priority
?
280 Views
Last Modified: 2012-08-13
how can I pass parameters between applets?
0
Comment
Question by:wchiang
[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
  • 4
  • 3
  • +2
14 Comments
 
LVL 6

Expert Comment

by:jpk041897
ID: 1244617
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.
0
 
LVL 6

Expert Comment

by:gadio
ID: 1244618
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.
0
 
LVL 8

Expert Comment

by:diakov
ID: 1244619
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
0
The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

 
LVL 6

Expert Comment

by:jpk041897
ID: 1244620
Gadio an DIakov are correct. I stand corrected.

Please reject this answer and give the points to Gadio.

cheers :-)
0
 

Author Comment

by:wchiang
ID: 1244621
Gadio,
Can you give an example including the static variable class?
Thanks,
wchiang
0
 

Author Comment

by:wchiang
ID: 1244622
Gadio,
were you waiting for an increase in points? Is 100 enough?
Thanks,
wchiang
0
 
LVL 8

Expert Comment

by:diakov
ID: 1244623
I can give an example, if gadio is away. Tell me...

Cheers,
  Nik
0
 

Author Comment

by:wchiang
ID: 1244624
diakov,
I assume Gadio is away somewhere so it'd be great if you can give an example.
Thanks,
wchiang
0
 
LVL 6

Expert Comment

by:jpk041897
ID: 1244625
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.
0
 
LVL 8

Expert Comment

by:diakov
ID: 1244626
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
0
 

Author Comment

by:wchiang
ID: 1244627
gadio,
please post your answer so I can give you the points.

diakov/jpk,
Thanks!
0
 
LVL 6

Accepted Solution

by:
gadio earned 400 total points
ID: 1244628
wchiang, I'm sorry I was not responsive. I seem to have not mark the notification checkbox. I'm posting my answer again. If you still need examples, let me know.

----------------

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.
0
 
LVL 8

Expert Comment

by:diakov
ID: 1244629
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
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6827390
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:
http://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.

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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

660 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