Ask Experts Questions for FREE Help !
Ask
    ahmedat's Avatar
    ahmedat Posts: 2, Reputation: 1
    New Member
     
    #1

    Nov 21, 2009, 02:42 AM
    How Do I correctly pass parms from html to applet
    I have a FORM, an Action HTML, and an Applet, but cannot seem to correly pass the parameters to the applet from the form. Below is the code I have for each file. What am I missing?

    Thx in advance,
    Ahmedat
    ----- FORM CODE ---------------

    <html>
    <head>
    <title>Histogram Tester</title>
    </head>
    <body>
    <hr>
    <h1>Histogram Tester</h1>

    <FORM METHOD=POST name="Form1" ACTION="GraphHist2.html">

    Enter a Title for the Histogram of Freq Polygon: <INPUT TYPE=text

    NAME="gTitle"><BR>
    Enter a Label for the x-axis: <INPUT TYPE=text NAME="xLabel"><BR>
    Enter a Label for the y-axix: <INPUT TYPE=text NAME="yLabel"><BR>

    Enter Number of Data Points: <INPUT TYPE=text NAME="numPts"><BR>
    Enter Number of Classes: <INPUT TYPE=text NAME="numClasses"><BR>
    <br>
    Enter Up to 22 Data Values (Leave unused ones blank)<br>
    Data Value 1: <INPUT TYPE=text NAME="bin0" SIZE = 6><BR>
    Data Value 2: <INPUT TYPE=text NAME="bin1" SIZE = 6><BR>
    Data Value 3: <INPUT TYPE=text NAME="bin2" SIZE = 6><BR>
    Data Value 4: <INPUT TYPE=text NAME="bin3" SIZE = 6><BR>
    Data Value 5: <INPUT TYPE=text NAME="bin4" SIZE = 6><BR>
    Data Value 6: <INPUT TYPE=text NAME="bin5" SIZE = 6><BR>
    Data Value 7: <INPUT TYPE=text NAME="bin6" SIZE = 6><BR>
    Data Value 8: <INPUT TYPE=text NAME="bin7" SIZE = 6><BR>
    Data Value 9: <INPUT TYPE=text NAME="bin8" SIZE = 6><BR>
    Data Value 10: <INPUT TYPE=text NAME="bin9" SIZE = 6><BR>
    Data Value 11: <INPUT TYPE=text NAME="bin10" SIZE = 6><BR>
    Data Value 12: <INPUT TYPE=text NAME="bin11" SIZE = 6><BR>
    Data Value 13: <INPUT TYPE=text NAME="bin12" SIZE = 6><BR>
    Data Value 14: <INPUT TYPE=text NAME="bin13" SIZE = 6><BR>
    Data Value 15: <INPUT TYPE=text NAME="bin14" SIZE = 6><BR>
    Data Value 16: <INPUT TYPE=text NAME="bin15" SIZE = 6><BR>
    Data Value 17: <INPUT TYPE=text NAME="bin16" SIZE = 6><BR>
    Data Value 18: <INPUT TYPE=text NAME="bin17" SIZE = 6><BR>
    Data Value 19: <INPUT TYPE=text NAME="bin18" SIZE = 6><BR>
    Data Value 20: <INPUT TYPE=text NAME="bin19" SIZE = 6><BR>
    Data Value 21: <INPUT TYPE=text NAME="bin20" SIZE = 6><BR>
    Data Value 22: <INPUT TYPE=text NAME="bin21" SIZE = 6><BR>
    <!INPUT TYPE=checkbox NAME="Dummy Checkbox">Dummy Checkbox <br>
    <!INPUT TYPE=button VALUE="Draw Freq Polygon"><br>
    <INPUT TYPE="SUBMIT" VALUE="Draw Histogram"><br>
    </FORM>
    <hr>
    </body>
    </html>
    ------------------ ACTION HTML (GraphHist2.html)--------
    <html>
    <head>
    <title>GraphHist2</title>
    </head>
    <body>
    <hr>
    <applet name=graphapp code=GraphHist.class width=600 height=400>
    </applet>
    <hr>
    </body>
    </html>
    ------------------ APPLET CODE (GraphHist.java)--------
    /*
    Class GraphHist */
    import java.awt.Graphics;
    import java.awt.Color;
    import java.awt.*;
    public class GraphHist extends java.applet.Applet {
    int nClasses = 1, nPts=1;
    float[ ] dataPts={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ,0};
    float[ ] Cnts={1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1} ;
    float[] cInterval={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ,0,0};
    String gTitle =" ";
    String xLbl=" ";
    String yLbl=" ";
    //double f(double x) {
    //return 3*(getSize().width/2-x) + getSize().height/2-20;
    //} //not used

    public void init() {
    int nPts, icWidth;
    double xmin, xmax, xmed, xavg;
    float[] A={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
    String param, param1="";
    String[] bintxt = {"bin0","bin1","bin2","bin3", "bin4", "bin5",

    "bin6","bin7",
    "bin8", "bin9", "bin10","bin11","bin12","bin13", "bin14", "bin15",

    "bin16","bin17","bin18","bin19","bin20","bin21 "};//can input up to 22 pts

    // Get graph title from user
    param = getParameter("gTitle");
    if (param != null) {
    gTitle = param;
    }
    else {
    gTitle = "< Insert Graph Title->";
    }
    // Get x-axis label from user
    param = getParameter("xLabel");
    if (param != null) {
    xLbl = param;
    }
    else {
    xLbl = "< Insert Label ->";
    }
    // Get y-axis label from user
    param = getParameter("yLabel");
    if (param != null) {
    yLbl = param;
    }
    else {
    yLbl = "< Insert Label ->";
    }

    // Get number of data pts from user
    param = getParameter("numPts");//Get num of classes from jscript file
    if (param != null) {
    nPts = Integer.parseInt(param);
    }
    else {
    nPts = 2;
    }
    // Get number of classes from user
    param = getParameter("numClasses");//Get num of classes from jscript file
    if (param != null) {
    nClasses = Integer.parseInt(param);
    }
    else {
    nClasses = 2;
    }
    // Get data Pts from user
    for (int I = 0 ; I < nPts ; I++) {
    param = getParameter(bintxt[i]);
    if (param != null) {
    dataPts[i] = Float.parseFloat(param);
    }
    else {
    dataPts[i] = 0;
    }
    }
    // gTitle= UserData.getgTitle();
    /* End Inputs --- Start Data Manipulations Section*/
    // Copy input data to a working array, and find avg of values
    xavg = AppletSRank.copyArrayPlus(nPts, dataPts, A);
    // Sort the working array A, and detm the median, min, and max
    xmed = AppletSRank.BSort(A, nPts);
    xmin = A[0];
    xmax = A[nPts-1];
    // Calc Class Width
    icWidth = (int) ((xmax - xmin)/(float)nClasses)+1;
    // Calc Class Interval Starts
    cInterval[0] = (float)xmin;
    for (int I = 1 ; I <= nClasses ; I++) {
    cInterval [i] = cInterval[i-1]+(float)icWidth;
    }
    //cInterval [nClasses] = (float)xmax;
    // Calc Interval (Bin) Counts
    for (int j = 0 ; j < nClasses ; j++) {
    Cnts[j] = 0;
    for (int I = 0 ; I < nPts ; I++) {
    if ((A[i]>=cInterval[j])&&(A[i]<cInterval[j+1])) {Cnts[j] +=1;}
    }
    }
    }
    /* End Data Manipulations -- Start Graphing Section*/
    public void paint(Graphics g) {
    double colWdth = 0,colHght=0;
    double xScl=0,maxCnt=0,minCnt=0;
    String str1;
    //Draw x-, y- axes, and border
    g.drawLine(0, 0, 0, getSize().height); //LS
    g.drawLine(0, 0, getSize().width, 0); //Top
    g.drawLine(0, getSize().height-1, getSize().width,

    getSize().height-1);//Bott
    g.drawLine(getSize().width-1, 0, getSize().width-1, getSize().height-1);

    //RS
    g.drawLine(0, getSize().height-30, getSize().width,

    getSize().height-30);//x-axis
    //draw y-ax tick marks ev 10 pts
    for (int y = 0 ; y < getSize().height-30 ; y+=10)
    {
    g.drawLine(0,y,5,y);
    }
    //debug stmts
    //g.setColor(Color.blue);
    //g.fillRect(10,40,150,200);
    //Detm max bin counts
    maxCnt = Cnts[0];
    for (int I = 1 ; I < nClasses ; I++)
    {
    maxCnt = (maxCnt > Cnts[i]) ? MaxCnt : Cnts[i];
    }
    xScl = (getSize().height-30)/(1.1*maxCnt);
    colWdth = (double)(getSize().width/(nClasses+2));
    g.setColor(Color.black);
    // Draw the histogram
    for (int I = 0 ; I < nClasses ; I++)
    {
    colHght = xScl * Cnts[i];
    g.drawRect((int)colWdth*(I+1), getSize().height-30-(int)colHght,(int)colWdth,

    (int)colHght);
    str1 = Float.toString(Cnts[i]);
    g.drawString(str1,(int)colWdth*(I+1)+3, getSize().height-30-(int)colHght);
    str1 = Float.toString(cInterval[i]);
    g.drawString(str1,(int)colWdth*(I+1)-4, getSize().height-18);
    }
    g.drawString(gTitle,getSize().width/3, 15);// Annotate graph with graph

    title

    g.drawString(xLbl,getSize().width/3, getSize().height-8);// Annotate graph

    with x-axis label
    }
    }
    jstrike's Avatar
    jstrike Posts: 418, Reputation: 44
    Full Member
     
    #2

    Dec 2, 2009, 08:26 AM

    You need to submit the form to a servlet to get the values. Right now you're posting it to an html page that has an applet running on it... that won't work.
    ahmedat's Avatar
    ahmedat Posts: 2, Reputation: 1
    New Member
     
    #3

    Dec 2, 2009, 12:59 PM

    Thx; I'll look into that.

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

Creating an Applet [ 1 Answers ]

Hi, Myself Lalita Lalwani, I want to know how to write an applet to show permanent passion between HTML and applet? Waiting for the reply...

Writing an Applet [ 1 Answers ]

Write an applet to show permanent passion between HTML and applet ? Thank you so much for helping me to find out the answers in advance :)


View more questions Search