Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / August 2004

Tip: Looking for answers? Try searching our database.

Two applets in the same web page

Thread view: 
JFA - 30 Aug 2004 16:45 GMT
Hi
I'm a french beginner in Java, so please forgive my poor knowledges and my
poor english.
I made an applet and put in in a jar file (named myjar.jar)
I wrote html like : <applet ... archive=myjar.jar> with some parameters.
In my applet I get these parameters with getParameter() and put them in
global variables :

I have a class named MyGlobalClass with static fields :
class MyGlobalClass{
   static String myField;}
and :
   MyGlobalClass.myField = getParameter(paramName);

Something strange happens :
When I run one instance of the applet at a time it works fine.
But when I run 2 instances of that same applet in the same html page with
different parameters these two instances seem to interfere with each other.
I wander if the the global variables of an applet are shared in the
computer.
What could I do to preserve the values of the variables of each instances ?
May be it is because I didn't override the stop method in my applet ?
Thank you for response
JFA
Andrew Thompson - 30 Aug 2004 17:29 GMT
> I'm a french beginner in Java, so please forgive my poor knowledges and my
> poor english.
> I made an applet ..

URL?

>..and put in in a jar file (named myjar.jar)
> I wrote html like : <applet ... archive=myjar.jar> with some parameters.
> In my applet I get these parameters with getParameter() and put them in
> global variables :
>
> I have a class named MyGlobalClass with static fields :

Why?  That would ensure every object of that class
would have access to only a single static field.
27 Objects -> 1 static field.

> Something strange happens :
> When I run one instance of the applet at a time it works fine.
> But when I run 2 instances of that same applet in the same html page with
> different parameters these two instances seem to interfere with each other.

Make those 'static' declarations, instance declarations,
then each time a class creates an object if that class,
it will have an unique gtoups of attributes / properties.

HTH

Signature

Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology

JFA - 30 Aug 2004 18:24 GMT
> > I have a class named MyGlobalClass with static fields :
>
> Why?  That would ensure every object of that class
> would have access to only a single static field.
> 27 Objects -> 1 static field.

Because I need that several classes share the access to this value.
For instance say that it's a font name and some Labels in Class1, Canvas in
Class2, etc. have to get this font name value.

> > Something strange happens :
> > When I run one instance of the applet at a time it works fine.
[quoted text clipped - 4 lines]
> then each time a class creates an object if that class,
> it will have an unique gtoups of attributes / properties.

If I create an instance of MyGlobalClass the problem will be the same with
that instance to be access from Class1, Class2, etc.
Where am I wrong ?
Is it not a good idea to have some values with global access ?
JFA
thufir.hawat@mail.com - 30 Aug 2004 19:54 GMT
[..]
>> Make those 'static' declarations, instance declarations,
>> then each time a class creates an object if that class,
[quoted text clipped - 5 lines]
> Is it not a good idea to have some values with global access ?
> JFA

perhaps you're thinking of a utility class, like Math.  Math constants
like pi (not an *exact* value, of course) yet there are no instances of
Math.  simply use a getter to get these primitives you seek?

my 2 cents.

Thufir Hawat
Real Gagnon - 31 Aug 2004 00:12 GMT
> What could I do to preserve the values of the variables of each
> instances ?

Just for fun, AFAIK adding the MAYSCRIPT to the Applet will do that as a
"side-effect".

Bye.
Signature

Real Gagnon  from  Quebec, Canada
* Looking for Java or PB snippets ? Visit Real's How-to  
* http://www.rgagnon.com/howto.html



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.