pass variable from an applet to another one

M

Marco

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?
 
T

Thomas Hawtin

Marco said:
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
 
M

Marco

If two applets are open by an html page as following:
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> said:
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?
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).
 
M

Marco

ERRATA-CORRIGE
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.
 
M

Marco

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");
}

//**************************************************
 
T

Thomas Hawtin

Marco said:
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).

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top