0

所以我搜索了很长时间关于如何使用此函数从我的小程序的 html 中检索 s 值的一些信息,但我没有找到太多。

基本上我想从命令行(当它作为应用程序运行时)或 html(当它作为小程序运行时)有 5 个参数。这是我的代码,Board 应用程序是一个小程序。它适用于应用程序,因为抛出 NullPointerException 并且它只是从命令行读取参数,但它不适用于小程序,它实际上什么都不做,空白屏幕。我还需要做什么才能让它发挥作用?

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);
    }
}

我的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>
4

1 回答 1

0

您需要在小程序标签的代码参数中传递您的实际小程序类(此处为 Board)。现在,为了同时在命令行和 http 下工作,您需要重新组织代码。也许在您的 Board 类中添加一个主要方法?

作为旁注,请注意您的 html,那里有一堆未关闭/重复的标签。

于 2014-05-23T00:57:34.530 回答