Novice question regarding passing Parameters from JavaScript to an Applet

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • timwap@yahoo.co.uk

    Novice question regarding passing Parameters from JavaScript to an Applet

    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

    #2
    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:-



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


    ========

    import java.awt.Font;
    import java.awt.Graphi cs;
    import java.util.Date;
    import java.applet.*;
    import java.awt.Graphi cs;
    import java.applet.Aud ioClip;

    public class Applet_1 extends java.applet.App let {

    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("TimesRoma n", Font.PLAIN, 18);

    String str = getParameter("t ext");
    String thour = getParameter("h our");
    String tmin = getParameter("m in");
    String tsec = getParameter("s ec");
    String ttone = getParameter("t one");

    g.setFont(f);
    //g.drawString(st r, 10, 25);
    g.drawString(th our, 10, 25);
    g.drawString(tm in, 10, 50);
    g.drawString(ts ec, 10, 75);
    g.drawString(tt one, 25, 25);

    do {
    Date CurrentTime = new Date();
    chour = CurrentTime.get Hours();
    cmin = CurrentTime.get Minutes();
    csec = CurrentTime.get Seconds();


    //g.drawString(cs ec, 75, 25);

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


    } while (hour != "00");


    System.out.prin tln("BEEP!");

    }
    }


    ========

    PS.
    I did not code the Java clock. That was a freebie from someone else ;)

    Comment

    • Laurent Bugnion, GalaSoft

      #3
      Re: Novice question regarding passing Parameters from JavaScriptto 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

      Comment

      • timwap@yahoo.co.uk

        #4
        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.

        Comment

        • Laurent Bugnion, GalaSoft

          #5
          Re: Novice question regarding passing Parameters from JavaScriptto 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

          Comment

          Working...