Calling applet from a java script

T

tomerdr

Hi,
I have an assignment in a java course in which i need to call an applet
from a java script.

The following is my script:

<applet name="MainApplet" id="MainApplet" code="MainApplet.class"
width="600" height="200" archive="MyApplets.jar">
<PARAM NAME="PictureFileName1" VALUE="Lilac.JPG">
<PARAM NAME="PictureFileName2" VALUE="Rose.JPG">
<PARAM NAME="RecipientName" VALUE="Juliet">
<PARAM NAME="SenderName" VALUE="Romeo">
<PARAM NAME="Greetings" VALUE="Happy birthday">
</applet>

<script language="JavaScript">
function UpdateAppletParams()
{
document.MainApplet.recipientName="test";
alert( document.MainApplet.recipientName);
document.MainApplet.repaint();
}
</script>


The following is part of my applet.it output a message on the screen
something like "hello [recipientName],[greetings], from
[senderName]..."

public class MainApplet extends java.applet.Applet {
public
Image image1;
Image image2;
String recipientName;
String senderName;
String greetings;
:
:
:

When calling the script and "debug" it with alert i can see that
document.MainApplet.recipientName='Test'
But the new message is not displayed.
i am running IE 7.0,XP PRO SP2,NETBEANS 5.5.


Thanks in advance.
 
P

Paul Hamaker

You can pass arguments to an applet from JS by calling public methods
in the applet.
 
A

Andrew Thompson

Hi,
I have an assignment in a java course in which i need to call an applet
from a java script.

I had written a long repsonse, even adding c.l.js. as
an x-post, before I realised that you are a multi-poster.
Dumped that reply, until we get this (more important
matter) sorted.

Please refrain from multi-posting.

(X-posted to c.l.j.p./c.l.js. w/ no follow-ups set)

Andrew T.
 
L

Lew

> 'recipientName' is a public property.

Not according to the code that you posted:
public class MainApplet extends java.applet.Applet {
public
Image image1;
Image image2;
String recipientName;

As you can see, 'recipientName' is declared as package-private in your code
sample, not public.

The usual idiom is to declare public accessor methods for private properties:

....
private String recipientName;
public getRecipientName()
{
return recipientName;
}

etc.

- Lew
 

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

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,816
Latest member
nipsseyhussle

Latest Threads

Top