next up previous
Next: 3 イベント処理 Up: 2 Interactive appletを作る Previous: 2.1 サイズの取得 getSize()

2.2 HTMLからパラメータの取得 getParameter

<html>
<body>
<center>
<applet code="Param"
  Width="300" Height="100">
<param name="message"
  value="HTMLからパラメータが取得する");
</applet>
</center>
</body>
</html>
// Param.java
import java.applet.*;
import java.awt.*;

public class Param extends Applet {
  public void paint(Graphics g) {
    String msg = getParameter("message");
    g.drawString(msg, 30, 20);
  }
}
<html>
<body>
<center>
<applet code="Param2"
  Width="300" Height="200">
<param name="x" value="200">
<param name="y" value="100">
</applet>
</center>
</body>
</html>
import java.applet.*;
import java.awt.*;

public class Param2 extends Applet {
  public void paint(Graphics g) {
    String strX = getParameter("x");
    String strY = getParameter("y");
    int x = Integer.parseInt(strX);
    int y = Integer.parseInt(strY);
    g.drawLine(0, 0, x, y);
  }
}
図 3: 数値パラメータを渡す例
\includegraphics[width=6cm]{/home/inaba/eps/lecture/fig/ParamPage.eps}


generated through LaTeX2HTML. M.Inaba 平成18年5月7日