Program to create an applet to accept a username as parameter and display number of characters.
In this program, we have to get the username from Applet's <PARAM> tag and display the length of the string. The value of parameter can be get using getParameter( ) method of applet. The length( )function is used to find length of given string.
PROGRAM
OUTPUT
C:\>javac CharCountParam.java
C:\>appletviewer CharCountParam.java
PROGRAM
import java.applet.Applet;
import java.awt.Graphics;
public class CharCountParam extends Applet{
String uname="", msg;
int length;
public void init()
{
uname = getParameter("Username");
length = uname.length();
uname = "Hello " + uname;
msg = "Length = " + length;
}
public void paint(Graphics g)
{
g.drawString(uname,50,50);
g.drawString(msg, 50, 90);
}
}
/*
<applet code="CharCountParam" width=200 height=200>
<param name="Username" value="RAHUL">
</applet>
*/
OUTPUT
C:\>javac CharCountParam.java
C:\>appletviewer CharCountParam.java
Comments
Post a Comment