Monday, October 25, 2010

Java applet tag parameters turtorials for beginners

 Pram tag in applet is used to pass parameter from applet tag to program..(See basic applet)
import java.awt.*;                                //importing awt,applet packages
import java.applet.*;
/*
<applet code="AppleParam" width="200" height="300">          
<param name=fontname value=Applet>                                       //passing parameter
<param name=fontsize value=>
</applet>
*/
public class AppleParam extends Applet{
String fontname;
int fontsize;
public void init(){
setBackground(Color.green);
setForeground(Color.red);
}
public void start(){
String param;
fontname=getParameter("fontname");
if(fontname==null)
fontname="No parameter";
param=getParameter("fontsize");
try{
if(param!=null)
fontsize=Integer.parseInt(param);
else
fontsize=0;
}

catch(Exception e){
System.out.println(e);
fontsize=-1;
}
}
public void paint(Graphics g){
g.drawString(" "+fontname,0,20);
g.drawString("Font size"+fontsize,0,40);
}
}

compile it with applet viewer or embed in web page.

Program for applet banner

No comments:

Post a Comment