QUESTION:
Write a program to Pass parameters embedding in HTML. (i.e Passing Parameters to Applets)
SOL:
CODE:
package com.p1;
import java.awt.Graphics;
import java.applet.Applet;
public class HelloWorld2 extends Applet
{
private String theDisplayString = "World";
private int theStartx = 10;
private int theStarty = 10;
public void init()
{
String tempName = this.getParameter("displayName");
String tempXString = this.getParameter("startx");
String tempYString = this.getParameter("starty");
if ((tempName!=null)&&(tempXString!=null)&&(tempYString!=null))
{
this.theDisplayString = tempName;
this.theStartx = (new Integer(tempXString)).intValue();
this.theStarty = (new Integer(tempYString)).intValue();
}
}
public void paint(Graphics g)
{
g.drawString("Hello "+theDisplayString+"!",theStartx,theStarty);
}
}
HTML CODE:
<title>TestAppletPage </title>
<hr>
<appletcode=HelloWorld2.classwidth=200height=100>
<param name=displayName value="JohnSmith">
<param name=startx value="50">
<param name=startyvalue="20">
</applet>
<hr>
OUTPUT:

applet.docx

  • 1.
    QUESTION: Write a programto Pass parameters embedding in HTML. (i.e Passing Parameters to Applets) SOL: CODE: package com.p1; import java.awt.Graphics; import java.applet.Applet; public class HelloWorld2 extends Applet { private String theDisplayString = "World"; private int theStartx = 10; private int theStarty = 10; public void init() { String tempName = this.getParameter("displayName"); String tempXString = this.getParameter("startx"); String tempYString = this.getParameter("starty"); if ((tempName!=null)&&(tempXString!=null)&&(tempYString!=null)) { this.theDisplayString = tempName; this.theStartx = (new Integer(tempXString)).intValue(); this.theStarty = (new Integer(tempYString)).intValue(); } } public void paint(Graphics g) { g.drawString("Hello "+theDisplayString+"!",theStartx,theStarty); } }
  • 2.
    HTML CODE: <title>TestAppletPage </title> <hr> <appletcode=HelloWorld2.classwidth=200height=100> <paramname=displayName value="JohnSmith"> <param name=startx value="50"> <param name=startyvalue="20"> </applet> <hr> OUTPUT: