Addition of two numbers using Java Applet

import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class add extends Applet
{
    TextField t1,t2;
    public void init()
    {
        t1=new TextField();
        t2=new TextField();
        add(t1);
        add(t2);
        t1.setText("0");
        t2.setText("0");
    }
    public void paint(Graphics g)
    {
        int x=0,y=0,z=0;
        String s,s1,s2;
        g.drawString("Enter a number in each box : ",10,50);
        try
        {
            s1=t1.getText();
            x=Integer.parseInt(s1);
            s2=t2.getText();
            y=Integer.parseInt(s2);
        }
        catch(Exception ex){}
        z=x+y;
        s=String.valueOf(z);
        g.drawString("The sum is : ",10,75);
        g.drawString(s,100,75);
    }
    public Boolean action(Object obj,Event eve)
    {
        repaint();
        return true;
    }
}




Top