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 / General / January 2006

Tip: Looking for answers? Try searching our database.

pass variable from an applet to another one

Thread view: 
Marco - 12 Jan 2006 14:38 GMT
If two applets are open by an html page as following:

<APPLET code="first.class" width=400 height=100></APPLET
<APPLET code="second.class" archive="second.jar" width=1 height=1></APPLET>

how can I understand when the second is loaded?

I must do one of the following:

1) setting, from second.class, to true the value of a boolean of
first.class.
2) undersand, from fist.class, when a frame created by second.class exists
[I used, in second.class, setName(String). Can be useful?]
3) Anothe way is welcome, if need

P.S. I need this work in Microsoft JVM too (1.4)...

It is possible?
Thomas Hawtin - 12 Jan 2006 16:13 GMT
> If two applets are open by an html page as following:
>
> <APPLET code="first.class" width=400 height=100></APPLET
> <APPLET code="second.class" archive="second.jar" width=1 height=1></APPLET>

The handling of applets is quite variable. I'm not sure if using
separate archive/codebases is going to upset things on some platforms.

> how can I understand when the second is loaded?

Get Second to find the First applet and call some method on it.

>  I must do one of the following:
>
> 1) setting, from second.class, to true the value of a boolean of
> first.class.

If you mean setting a static variable, don't. static variables mean
trouble, particularly when it comes to applets.

> 2) undersand, from fist.class, when a frame created by second.class exists
> [I used, in second.class, setName(String). Can be useful?]

Again, get Second to call some method of First. Frames don't work too
well with applets·

> 3) Anothe way is welcome, if need
>
> P.S. I need this work in Microsoft JVM too (1.4)...

I suggest the only support you give for the Microsoft JVM is to display
a message telling the user to disable it at once. If you run the
Microsoft JVM then your machine is insecure. There's enough zombie
machines out there as it is.

Tom Hawtin
Signature

Unemployed English Java programmer
http://jroller.com/page/tackline/

Marco - 12 Jan 2006 17:29 GMT
>> If two applets are open by an html page as following:
>>
>> <APPLET code="first.class" width=400 height=100></APPLET
>> <APPLET code="second.class" archive="second.jar" width=1
>> height=1></APPLET>

I rewrite this:

<APPLET code="first.class" name="first" width=400 height=100></APPLET
<APPLET code="second.class" archive="second.jar" neme="second" width=1
height=1></APPLET>

> Get Second to find the First applet and call some method on it.

I set in the first class:

public void finish()
{this.finish=true;}

...in the second one:

try
{
 AppletContext ac = getAppletContext();
 first f=(first)ac.getApplet("first");
 f.fatto();
}
catch (Exception e)
{System.out.println("Error "+e);}

(as the example at http://www.mokabyte.it/1999/05/AppletNoFrame.htm)
But the result is the following:

Error java.lang.ClassCastException: first
(JVM Microsoft 1.1.4)
Error java.security.AccessControlException: access denied
(java.util.PropertyPermission java.home read)
(JVM SUN 1.5.0_02)

How can I access public methods of first applet from second, without signing
applet?

>> P.S. I need this work in Microsoft JVM too (1.4)...
>
> I suggest the only support you give for the Microsoft JVM is to display a
> message telling the user to disable it at once. If you run the Microsoft
> JVM then your machine is insecure. There's enough zombie machines out
> there as it is.

This is rigth, but my problem is that many user of Internet have only
Microsoft JVM, and I think that many of them want not install SUN Java only
for visualize an applet on a website.
I need this work with all version of Java (from 1.1 to 1.5).
Marco - 12 Jan 2006 17:47 GMT
ERRATA-CORRIGE

> neme="second"
name="second"

>  f.fatto();
f.finish();

Excuse me.
Marco - 12 Jan 2006 18:02 GMT
> ERRATA-CORRIGE
>
[quoted text clipped - 3 lines]
>>  f.fatto();
> f.finish();

N.B. It is wrong only my message to this newsgroup, the original code that I
tested id ok (here I translate from Italian same name in my code), but the
runtime error is as I reported. I haven't resolved my problem.
Marco - 12 Jan 2006 21:35 GMT
>> how can I understand when the second is loaded?
>
> Get Second to find the First applet and call some method on it.

I find two differents methods for call, from an applet, a method of another
applet of the same html page, but they work only if I have two class files;
I, instead, have a class file and a jar one, and another the following
methods don't properly work.

The result is always the same: from the init of main class of the jar I find
a class named 'first' but the JVM don't recognize it as instance of first
(then, I cannot apply his methods).

HELP!

1)
//**************************************************
Enumeration appletList=getAppletContext().getApplets();
while (appletList.hasMoreElements())
{
 Applet applet=(Applet)appletList.nextElement();
 if (applet instanceof first)
  {
   System.out.println("I find the first class");
   ((first)applet).mymethod();
  }
 else
  {
   if (applet instanceof second)
    {
     System.out.println("I find second class");
    }
   else
    {
     System.out.println("This isn't first or second class");
    }
  }
}
//**************************************************
2)
//**************************************************
Applet a=null;
String nome="first";
a=getAppletContext().getApplet(nome);
if (a!=null)
{
 if (!(a instanceof first))
  {
   System.out.println("I find an applet named "+nome+", but it isn't an
object of type 'first'.\n");
  }
 else
  {
   System.out.println("I find an applet named "+nome+"; it is that you
search.\n");
   ((first)a).mymethod();
  }
}
else
{
 System.out.println("I haven't find any applet named "+nome+".\n");
}

//**************************************************
Thomas Hawtin - 12 Jan 2006 22:56 GMT
>>>how can I understand when the second is loaded?
>>
[quoted text clipped - 8 lines]
> a class named 'first' but the JVM don't recognize it as instance of first
> (then, I cannot apply his methods).

Have you tried using exactly the same archive attribute for both
applets? I can't find any decent documentation on what is expected from
the aplet container at the moment.

Alternatively you can implement a standard interface (like Runnable),
and check a stream in the AppletContext when that has been called.
Something like:

class Second extends java.applet.Applet {
    @Override
    public void init() {
        getAppletContext().setStream("my-key", createStream());
        ((Runnable)getFirstApplet()).run();
    }
    ...
}
class First extends java.applet.Applet implements Runnable {
    public void run() {
        handleStream(getAppletContext().getStream("my-key"));
    }
    ...
}

Disclaimer: Not even compiled, let alone tested. I haven't played with
this sort of thing since 1.02.

Tom Hawtin
Signature

Unemployed English Java programmer
http://jroller.com/page/tackline/



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.