Re: java.applet.Applet.getParameter()
Here is the way I deal with applet parameters
public enum Param
{
PARAM1( new String( "string" ) )
{ Object getValue( Applet a ) { return super.getValue( a ); } },
PARAM2( new Integer( 1 ) )
{ Object getValue( Applet a ) { return super.getValue( a ); } },
PARAMn( new Double( 1.2 ) )
{ Object getValue( Applet a ) { return super.getValue( a ); } };
protected Object v = null;
private Param( Object defValue )
{
this.v = defValue;
}
Object getValue( Applet a )
{
Object v2 = a.getParameter( this.toString() );
return (v2 == null) ? this.v : v2;
}
}
public MyApplet extends Applet
{
/* ....... */
public void start()
{
/* ....... */
string theValue = Param.PARAM1.getValue();
/* ....... */
}
/* ....... */
}
blaine@worldweb.com wrote:
I would like to test to see if a parameter exists in the html file
prior to calling getParameter(<key>), however I can not find any sort
of method to allow me to do this.
Is there a containsKey() method or something similar so that I could
write code like:
String[] keys = {"key1","key2"};
Hashtable ht = new Hashtable();
for(int i = 0; keys.length > i; i++){
if ( <KEY EXISTS IN HTML PARAMETER LIST> ){
ht.put(keys[i], getParameter(keys[i]);
}
}
I know that I could just "try" and "catch" the getParameter, but this
does not seem as clean as just doing a test for existence.
Any help would be appreciated.