Java Tutorial

 
 
 
 
/* <applet code=\"sumOf2No\" height=150 width =350>
   </applet> */

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

public class sumOf2No extends Applet
{
     TextField T1,T2;

     public void init() {
         T1 = new TextField(10);
         T2 = new TextField(10);
         add(T1);
         add(T2);
         T1.setText(\"0\");
         T2.setText(\"0\");
      }

      public void paint(Graphics g) {
           int a, b, result;
           String str;

           g.drawString(\"Enter Number in TextField to Find addition of 2 No \",10,50);
           g.setColor(Color.red);
           str=T1.getText();
           a=Integer.parseInt(str);
           str=T2.getText();
           b=Integer.parseInt(str);
           result=a+b;
           g.drawString(\"After Addition the Result is : \"+result,10,80);
           showStatus(\"Addition of 2 Numbers\");
        }

        public boolean action(Event e, Object o){
            repaint();
            return true;
        }
}

 
 
Didn't find what you were looking for? Find more on An applet program to display sum of two number of textField