SDSU CS 596 Java Programming
Fall Semester, 1998
Parameter Applet
To Applet Index
San Diego State University -- This page last updated 16-Dec-98

Description

This applet shows passing information from the HTML to the applet via PARAM tag.

Applet

Your browser does not support Java applets, so you can not see this applet operate.

Applet Tag

<APPLET archive="AppletClasses.jar" 
   code="ParameterApplet.class" width=300 height=200>
      <param name="name" value="Roger">
      <param name="yourHeight" value="5">
   Your browser does not support Java applets, so
   you can not see this applet operate.
</APPLET>

Applet Source Code

ParameterApplet.java

import java.awt.*;
import java.applet.Applet;

public class ParameterApplet extends Applet
  {
  // Used to show information
  TextArea messages = new TextArea(8, 20);
        
  public void init() 
    {
    add( messages );
    
    // Here is where the parameter values are read.
    String name = getParameter( "name" );
    int height = Integer.valueOf (getParameter( "yourHeight" )).intValue();
    messages.append( "name: " + name + "\n" );
    messages.append( "height: " + height + "\n" );
    }

  // Used in appletviewer to give some information about
  // the applet
  public String getAppletInfo() 
    {
    return "This applet shows how to pass information" +
      " from the html document to the applet";
    }
  
  // Appletviewer uses this to display info about parameters
  public String[][] getParameterInfo() 
    {
    return new String[][] {
        { "name" , "string", "your name" },
        { "yourHeight", "int" , "your height"}
      };
    }
    
  public void paint( Graphics display ) 
    {
    // Draw border
    Dimension size = getSize();
    display.drawRect( 0, 0, size.width-1, size.height-1);
    }
  }


Visitors since 16-Dec-98