Write a program in java to display addition of two numbers in applet and numbers must be given at compile time?

import java.applet.*;

import java.awt.*;

/*

      <applet code="ParamApplet" width=400 height=300>

      <param name="num1" value=20>

      <param name="num2" value=30>

      </applet>

*/

public class ParamApplet extends Applet

{

      int a,b,c;

      public void init()

      {

            setBackground(Color.red);

            setForeground(Color.yellow);

            a=Integer.parseInt(getParameter("num1"));

            b=Integer.parseInt(getParameter("num2"));

            c=a+b;

      }

      public void paint(Graphics g)

      {

            g.drawString("Sum = "+c,175,150);

      }

}

Display Addition of Two Number (Applet).PNG

, , , , ,

Leave a Reply