0

so I searched a long time for some info about how to use this function to retrieve values of s from html for my applet but I have not found much.

Basically I want to have 5 arguments from either command line (when its run as app) or html (when its run as applet). Here is my code, Board app is an applet. It works fine for app, because NullPointerException is thrown and it just reads arguments from command line, but it does not for applet, it actually does nothing at all, blank screen. What else do I have to do to make it work?

Board app=new Board();  
try{    
    x = Integer.parseInt(app.getParameter("x"));
    y = Integer.parseInt(app.getParameter("y"));
    delay = Integer.parseInt(app.getParameter("delay"));
    wolfNumber = Integer.parseInt(app.getParameter("wolves"));
    hareNumber = Integer.parseInt(app.getParameter("hares"));
}

catch(NullPointerException exec){


    try{
        x = Integer.parseInt(args[0]);
        y = Integer.parseInt(args[1]);
        delay = Integer.parseInt(args[2]);
        wolfNumber = Integer.parseInt(args[3]);
        hareNumber = Integer.parseInt(args[4]);
        if(args.length<5) throw new NumberFormatException();

    }

    catch(NumberFormatException ex){ 
        JOptionPane.showMessageDialog(null,"Nie podano odpowiednich parametrow","Error",JOptionPane.WARNING_MESSAGE);
        System.exit(0);
    }

    catch(ArrayIndexOutOfBoundsException exe){ 
        JOptionPane.showMessageDialog(null,"Nie podano odpowiednich parametrow","Error",JOptionPane.WARNING_MESSAGE);
        System.exit(0);
    }
}

my html:

<html>
  <head>
      <title>Simulator</title>
  </head>
  <body>
    <center>
      <h1>Simulator</h1>
      <hr>
    <APPLET ARCHIVE="Main.jar" CODE="Main.class" WIDTH=500 HEIGHT=500>
    <PARAM name="x" value="64">
    <PARAM name="y" value="64">
    <PARAM name="delay" value="400">
    <PARAM name="wolves" value="20">
    <PARAM name="hares" value="100">
    </APPLET>
      </applet>
      <hr>
    </center>
  </body>
</html>
user3369008
  • 105
  • 11

1 Answers1

0

You need to pass your actual applet class (here, Board) in the code param of the applet tag. Now in order to work both at the command line AND http, you will need to reorganize your code. Maybe add a main method to your Board class ?

And as a side note, pay attention to your html, there is a bunch of unclosed/duplicate tags there.

Mathieu Fortin
  • 1,048
  • 7
  • 17