Appletタグ内のパラメーターにアクセスする方法
この例では、アプレットが「Applet.getParameter()」メソッドを使用してアプレットのタグ内のパラメータ(「paramWidth」、「paramHeight」、「paramUrl」)を読み取る方法を確認します。
1. アプレットクラスを作成する
アプレットクラスを作成し、getParameter()メソッドでアプレットのパラメーターを取得します。
package com.example.applet; import java.applet.*; import java.awt.Graphics; public class AppletExample extends Applet { String paramWidth; String paramHeight; String paramUrl; public void init() { paramWidth = this.getParameter("paramWidth"); paramHeight = this.getParameter("paramHeight"); paramUrl = this.getParameter("paramUrl"); } public void paint( Graphics g ) { StringBuffer sb = new StringBuffer() .append(" width : ").append(paramWidth) .append(" height : ").append(paramHeight) .append(" url : ").append(paramUrl); g.drawString(sb.toString(), 0,100); } }
2. HTMLページを作成する
Testing
3. Done
実行すると、次の出力が表示されます。
width : 300 height : 300 url : http://www.example.com