Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing contents of a variable to a Java applet as a parameter.

Status
Not open for further replies.

waynea

Programmer
Jul 11, 2000
41
US
I'm building the data by concatenating the contents of five form fields with a literal suffix.  The data is built OK, but no matter which way I phrase the PARAM line, the variable name gets passed rather than the contents.  What the heck am I missing here?  This is only a single field to pass, so it shouldn't be this complicated.
 
Dear waynea,<br><br>I cannot even begin to understand how you think we can help if you don't post some small portion of the code that is in question.<br><br>&quot;But, that's just my opinion... I could be wrong&quot;.<br>-pete
 
OK, here's a code sample.&nbsp;&nbsp;&quot;current.mpg&quot; needs to be replaced with the contents of a field called &quot;strHistName&quot; which should be in the format yyyymmddhhmm.mpg.&nbsp;&nbsp;My test file is named &quot;200001052100.mpg&quot; and strHistName DOES contain this data, but I have not been able to pass the contents through - anything I enter gets passed as a literal string.<br><br>&lt;APPLET CODE=&quot;MPEG_Play.class&quot; WIDTH=255 HEIGHT=310 style=&quot;border-style: solid; border-width: 5&quot;&gt;<br>&lt;PARAM NAME=FILENAME VALUE=&quot;current.mpg&quot;&gt;<br>&lt;PARAM NAME=DELAY VALUE=&quot;user&quot;&gt;<br>&lt;/APPLET&gt;
 
what programming or scripting language is <FONT FACE=monospace>strHistName</font> a variable of? Where are you determining the value of it? If it's in quotes, that's how it's getting past in... <p>Liam Morley<br><a href=mailto:lmorley@wpi.edu>lmorley@wpi.edu</a><br><a href=] :: imotic :: website :: [</a><br>"light the deep, and bring silence to the world.<br>
light the world, and bring depth to the silence.
 
Wayne
Did you ever solve this problem? I have almost an identical need to pass the contents of a varible to the Param of an applet. I haven't found any way to do it either. I've been trying to set the value of the Applet object.document.name.object.value = John Jones. But I don't think the param can be addressed as an object. I'm going to post a similar request and see if I can get any more interest...It's possible the way the applet is passed the parameters, that we cant do this.

Burr Stephens
 
Hi, waynea!

There are two ways of doing this, depending of what you want:
1. Static: :-9
Code:
   <APPLET CODE=&quot;MPEG_Play.class&quot; WIDTH=255 HEIGHT=310 style=&quot;border-style: solid; border-width: 5&quot;>
   <script language=&quot;JavaScript&quot;>
   document.write(&quot;<PARAM NAME=FILENAME VALUE=\&quot;&quot; + strHistName + &quot;\&quot;>&quot;);
   </script>
   <PARAM NAME=DELAY VALUE=&quot;user&quot;>
   </APPLET>

2. Dynamic: :)I
It will be somewhat more difficult. Because you need to rewrite applet, or at least you need to know public property/method of class MPEG_Play.
For more information look at Netscape DevEdge:

PS: All this of cause can be translated to VBScript if you are crazy about it.
 
Michael Dubner,
Thanks for your input. I joined this thread because I have an identical programming problem. I have used your method before and it works very well when I apply it to other HTML tags. When I use it for the Param of an Applet, it is just ignored. I'm guessing the way the Params are passed to the Applet, it is ignoring the document.write statement. If any one can verify this, please reply. Where can I get more info about the Applet param? All the documents I find are not very detailed on the subject. Here is some code fragments that show what I want to do and what I have found that doesn't work...

This is an applet from Front Page 97. It is a button with a url attached.This applet works and the url, Jun2000.htm is an active url when the button is clicked.

<applet code=&quot;fphover.class&quot; codebase=&quot;_fpclass&quot; width=&quot;70&quot; height=&quot;30&quot;>
<param name=&quot;url&quot; value=&quot;Jun2000.htm&quot; valuetype=&quot;ref&quot;>
</applet>

This is the same applet with your document.write code applied. The url is ignored. If it would work, I would substitute the Jun2000.htm with a varible as you showed in the example. I want the url to change relative to the month.

<applet code=&quot;fphover.class&quot; codebase=&quot;_fpclass&quot; width=&quot;70&quot; height=&quot;30&quot;> <script language=&quot;JavaScript&quot;>
document.write(&quot;<param name=\&quot;url\&quot; value=\&quot;Jun2000.htm\&quot; valuetype=\&quot;ref\&quot;>&quot;);
</script>
</applet>

Do I have something different in my browser that is preventing this to work? Netscape 4.73 and Explorer 5.0 will neither show this is working.

Any one with any ideas?


 
Actually, yes, I got the solution. What I did was modify the Java program itself to add the following code:

/*------------------------------------------------------- */
/* This method created 7/17/2000 by CWA to pass user-selected filename into applet */
public void setFileName(String strFileName) {
stopanim();
showFileName.setLabel(strFileName);
restart(strFileName);
}


strFileName is the name within the Java applet of the parameter being passed in; the restart routine starts the applet over using the new filename. Then in the HTML code I built the new filename and passed it in to the applet using the following code:

function passname()
{
document.applets.MP.setFileName(strFileName);
return strFileName;
}

Hope this helps out. I'm not a Java programmer by any means, but this worked.
 
There may be an additional way to do this, for conveince B-). You can have the java applet call and pass a function back to the browser. Again i have only tested this once on IE5 and it works, i have no idea on other systems.
In java applet
try
{
AppletContext context = getAppletContext();
URL u = new URL(getCodeBase(),&quot;JavaScript:// something(value)&quot;);
context.showDocument(u,frame);
}
catch(Exception error)
{
showStatus(&quot;Error &quot; + error);

So basically you can bring in the names of functions as parameters and then have the applet call them, technically (|:)> .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top