Connecting Tech Pros Worldwide Forums | Help | Site Map

Novice question regarding passing Parameters from JavaScript to an Applet

timwap@yahoo.co.uk
Guest
 
Posts: n/a
#1: Jul 20 '05
I hava a Java Applet that produces a DTMF tone at a certain time of
day.
There are 4 parameters to the Applet, they are
hour = Hour of triggered event 00~23
min = minute of triggered event 00~59
sec = Second of triggered event 00~59
tone = DTMF Tone to play 0~9 A~F # & *

I now need to write a HTML/JavaScript web page that will enable me to
pass these 4 parameters to the applet.
I do know that the code to pass the values will be something like
this:-

<APPLET CODE="ToneTrig.class" WIDTH=100 HEIGHT=100>
<PARAM NAME="hour" VALUE= value selected in a drop down form menu>
<PARAM NAME="min" VALUE = value selected in a drop down form menu>
etc etc etc
</APPLET>

The bit I'm unsure about is how to have the JavaScript wait till you
have selected the required vales then proceed to trigger the applet.
Does it have to be in the shape of a form or is a simple button
needed?

I'm very new to JavaScript & Java coding so please try and explain it
in a way that a newbie may understand ;)

Many thanks.

timwap@yahoo.co.uk
Guest
 
Posts: n/a
#2: Jul 20 '05

re: Novice question regarding passing Parameters from JavaScript to an Applet


Wow. Thanks for that.

It's going to take me a while to assimilate that knowledge.

Still a bit confused in the script as to what is a variable and what
is a command. But will fugure it out I'm sure.

Perhaps you could take a look at what I've done so far at the
following address & script and tell me where I'm going wrong:-

http://www.entropy1024.pwp.blueyonder.co.uk/DTMF/

This JavaScript should then pass the 4 variables to the following
Applet.


========

import java.awt.Font;
import java.awt.Graphics;
import java.util.Date;
import java.applet.*;
import java.awt.Graphics;
import java.applet.AudioClip;

public class Applet_1 extends java.applet.Applet {

int chour, cmin, csec = 0;

String str = "Default";
String hour = "Default";
String min = "Default";
String sec = "Default";
String tone = "Default";
public void paint(Graphics g) {
Font f = new Font("TimesRoman", Font.PLAIN, 18);

String str = getParameter("text");
String thour = getParameter("hour");
String tmin = getParameter("min");
String tsec = getParameter("sec");
String ttone = getParameter("tone");

g.setFont(f);
//g.drawString(str, 10, 25);
g.drawString(thour, 10, 25);
g.drawString(tmin, 10, 50);
g.drawString(tsec, 10, 75);
g.drawString(ttone, 25, 25);

do {
Date CurrentTime = new Date();
chour = CurrentTime.getHours();
cmin = CurrentTime.getMinutes();
csec = CurrentTime.getSeconds();


//g.drawString(csec, 75, 25);

if (sec == tsec)
if (min == tmin)
break;
else {
}
else {
}


} while (hour != "00");


System.out.println("BEEP!");

}
}


========

PS.
I did not code the Java clock. That was a freebie from someone else ;)
Laurent Bugnion, GalaSoft
Guest
 
Posts: n/a
#3: Jul 20 '05

re: Novice question regarding passing Parameters from JavaScript to an Applet


Hi,

timwap@yahoo.co.uk wrote:[color=blue]
> Wow. Thanks for that.
>
> It's going to take me a while to assimilate that knowledge.
>
> Still a bit confused in the script as to what is a variable and what
> is a command. But will fugure it out I'm sure.
>
> Perhaps you could take a look at what I've done so far at the
> following address & script and tell me where I'm going wrong:-
>
> http://www.entropy1024.pwp.blueyonder.co.uk/DTMF/
>
> This JavaScript should then pass the 4 variables to the following
> Applet.[/color]

With this applet (code snipped), you have no way to pass the parameters
dynamically (using LiveConnect) because the applet has no public method
allowing you to do so. Modifying the applet would be trivial, but...
probably not possible for you (no offense ).

I would simply use my second proposal (the document.write) if I were you.

HTH,

Laurent
--
Laurent Bugnion, GalaSoft
Webdesign, Java, javascript: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch

timwap@yahoo.co.uk
Guest
 
Posts: n/a
#4: Jul 20 '05

re: Novice question regarding passing Parameters from JavaScript to an Applet


Thanks again for the guidance. I feel I'm so close to getting this
thing working but still keep falling down.

Your JavaScript, although intimidating to the likes of me, does make
sense. The bit I have trouble understanding is the following line.

document.write( strAppletCode );

A few lines above is the command 'var strAppletCode =...' so I guess
strAppletCode is a variable. It also looks like this variable will be
loaded with the Applet code & name, width & height plus hour, min, sec
& tone parameters.

So if I had selected a trigger time of 10:20:30 and the tone 'A' then
strAppletCode would contain the following info:
'<APPLET CODE="ToneTrig.class" WIDTH="100" HEIGHT="100">', 10, 20, 30,
A

Is this anywhere near right? I hope so ;)

Then 'document.write( strAppletCode );' would pass this data to the
applet. I have not been able to find any reference to the
'document.write' command in my Jscript manual. Thats if it is a
command.

What do I need to put in my Applet to get it to recieve these
variables? Is it the 'getParameter' command or something else? I
suspect the latter.

Many thanks.
Laurent Bugnion, GalaSoft
Guest
 
Posts: n/a
#5: Jul 20 '05

re: Novice question regarding passing Parameters from JavaScript to an Applet


Hi,

timwap@yahoo.co.uk wrote:[color=blue]
> Thanks again for the guidance. I feel I'm so close to getting this
> thing working but still keep falling down.
>
> Your JavaScript, although intimidating to the likes of me, does make
> sense. The bit I have trouble understanding is the following line.
>
> document.write( strAppletCode );[/color]

The method document.write() writes some HTML code into the current
document. This HTML code is then interpreted by the browser. It is
handled as if it was normal HTML code.

[color=blue]
> A few lines above is the command 'var strAppletCode =...' so I guess
> strAppletCode is a variable. It also looks like this variable will be
> loaded with the Applet code & name, width & height plus hour, min, sec
> & tone parameters.[/color]

The variable strAppletCode is a String of characters, which contains
exactly this code:

<APPLET CODE="ToneTrig.class" WIDTH="100" HEIGHT="100">
<PARAM NAME="hour" VALUE="HH">
<PARAM NAME="min" VALUE="MM">
<PARAM NAME="sec" VALUE="SS">
<PARAM NAME="tone" VALUE="TT">
</APPLET>

However, it is built dynamically, and the HH, MM, SS and TT are replaced
by (resp.) Hour, Minutes, Seconds and Tone chosen by the user.

[color=blue]
> So if I had selected a trigger time of 10:20:30 and the tone 'A' then
> strAppletCode would contain the following info:
> '<APPLET CODE="ToneTrig.class" WIDTH="100" HEIGHT="100">', 10, 20, 30,
> A[/color]

Rather:

<APPLET CODE="ToneTrig.class" WIDTH="100" HEIGHT="100">
<PARAM NAME="hour" VALUE="10">
<PARAM NAME="min" VALUE="20">
<PARAM NAME="sec" VALUE="30">
<PARAM NAME="tone" VALUE="A">
</APPLET>

[color=blue]
> Is this anywhere near right? I hope so ;)
>
> Then 'document.write( strAppletCode );' would pass this data to the
> applet. I have not been able to find any reference to the
> 'document.write' command in my Jscript manual. Thats if it is a
> command.[/color]

It doesn't pass it to the applet, it writes the HTML code for the
applet, including the parameters. The browser then starts the applet,
which gets the parameters (using getParameter, as you found out) and
handles them.
[color=blue]
> What do I need to put in my Applet to get it to recieve these
> variables? Is it the 'getParameter' command or something else? I
> suspect the latter.[/color]

I believe it should work fine.
[color=blue]
>
> Many thanks.[/color]

No probs,

Laurent
--
Laurent Bugnion, GalaSoft
Webdesign, Java, javascript: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch

Closed Thread