Passing parameters to Applet

Parameter in Applet

We can get any information from the HTML file as a parameter. For this purpose, Applet class provides a method named getParameter(). Syntax:
  1. public String getParameter(String parameterName)  

Example of using parameter in Applet:

  1. import java.applet.Applet;  
  2. import java.awt.Graphics;  
  3.   
  4. public class UseParam extends Applet{  
  5.   
  6. public void paint(Graphics g){  
  7. String str=getParameter("msg");  
  8. g.drawString(str,5050);  
  9. }  
  10.   
  11. }  

myapplet.html

  1. <html>  
  2. <body>  
  3. <applet code="UseParam.class" width="300" height="300">  
  4. <param name="msg" value="Welcome to applet">  
  5. </applet>  
  6. </body>  
  7. </html>  

No comments:

Post a Comment