そのため、この関数を使用してアプレットの 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>