Addition


import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
< applet code = "Applet10" width = 400 height= 200 >
< /applet>
*/
public class Applet10 extends Applet implements ActionListener
{
    TextField no1, no2, no3,no4; public void init()
    {
        Label no1a = new Label("Number	1 : ", Label.RIGHT);	
        Label no2a = new Label("Number	2 : ", Label.RIGHT);	
        Label no3a = new Label("Number	3 : ", Label.RIGHT);	
        Label no4a = new Label("Number	4 : ", Label.RIGHT);	

        no1 = new TextField(10);
        no2 = new TextField(10);
        no3 = new TextField(10);
        no4 = new TextField(10);

        add(no1a);
        add(no1); 

        add(no2a); 
        add(no2); 

        add(no3a); 
        add(no3); 

        add(no4a); 
        add(no4);
        
        no1.addActionListener(this); 
        no2.addActionListener(this); 
        no3.addActionListener(this); 
        no4.addActionListener(this);
    }
    public void actionPerformed(ActionEvent ae)
    {
        repaint();
    }
    public void paint(Graphics g)
    {
        g.drawString("Number 1 : " +no1.getText(), 6, 100);	
        g.drawString("Number 2 : " +no2.getText(), 6, 120);	
        g.drawString("Number 3 : " +no3.getText(), 6, 140);	
        g.drawString("Number 4 : " +no4.getText(), 6, 160);	
  
        int num1 = Integer.parseInt(no1.getText());
        int num2 = Integer.parseInt(no2.getText());
        int num3 = Integer.parseInt(no3.getText());
        int num4 = Integer.parseInt(no4.getText());

        int t = num1 + num2 + num3 + num4;

        g.drawString("Total: " + t, 6, 180);

    }
}
    

Output: