Java Blog

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

public class textFieldDemo extends Applet
{
      String str;
      int a,b,result;
      TextField t1,t2;   //Creating Object of TextField Class
      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)
     {
          str=t1.getText();
          a=Integer.parseInt(str);
          str=t2.getText();
          b=Integer.parseInt(str);
          result=a+b;
          str=String.valuOf(result);
          g.drawString(\"Addition of both the field is :  \"+str,0,100);
     }
}

 
 
Didn't find what you were looking for? Find more on An applet program to add two numbers where data is entered in TextField