Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Applet and Parameter Passing

Program

To find the sum of two numbers using Applet parameter passing.

Algorithm

Step 1: Start
Step 2: Write html code for applet and initialize parameters s1=10 and s2=20
Step 3: Start applet by calling init() and paint(Graphics g)
Step 4: Stop

Function public void init()

Step 1: Start
Step 2: s1=value of parameter s1 from applet
Step 3: s2=value of parameter s2 from applet
Step 4: a=intiget representation of s1
Step 5: b=integer representation of s2
Step 6: c=a+b
Step 7: sum=string representation of c
Step 8: exit

Function public void init()

Step 1: Start
Step 2: Draw string sum on applet
Step 3: Exit.

Program
/*
*/

import java.applet.Applet;
import java.awt.*;

public class MyAppParm extends Applet
{  
    	String s1,s2,sum;
    	int a,b,c;

    	public void init() 
    	{
      		s1=getParameter("s1");
       	 	s2=getParameter("s2");
        		a=Integer.parseInt(s1);
        		b=Integer.parseInt(s2);
        		c=a+b;
    		sum=String.valueOf(c);  
    	}

    	public void paint(Graphics g) 
   	{
       	 	g.drawString("Sum : " + sum,20,50);
    	}
}

Applet and Parameter Passing is a post from ShoutToWorld - Let's Learn Let's Shout - Helping bloggers and developers.



This post first appeared on ShoutToWorld, please read the originial post: here

Share the post

Applet and Parameter Passing

×

Subscribe to Shouttoworld

Get updates delivered right to your inbox!

Thank you for your subscription

×