An Applet Program to Add Two Numbers

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

public class addition extends Applet
{
Label l1,l2,l3;
TextField t1,t2,t3;
Button b;

int x,y,z;

public void init()
{
l1 = new Label("mark 1");
t1 = new TextField(10);

l2 = new Label("mark 2");
t2 = new TextField(10);

l3 = new Label("total");
t3 = new TextField(10);

b = new Button("add");
b.addActionListener(new test());

add(l1); add(t1);
add(l2); add(t2);
add(l3); add(t3);
add(b);
}

class test implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == b)
{
x = Integer.parseInt(t1.getText());
y = Integer.parseInt(t2.getText());
z = x+y;
t3.setText(String.valueOf(z));
}
} 
}
}

Recommended Posts:

Advanced Java
1. Java Applet
2. Applet Life Cycle in Java
3. Difference Between Applet and Application
4. Creating an Executable Applet in Java
5. Displaying Numerical values in Applet
6. An Applet Program to Add Two Numbers
7. Event Handling in Applet
8. AWT Event Classes
9. AWT Graphics Class
10. Draw a line and rectangle in Java Applet
11. Draw Circles and Ellipses in Java Applet
12. Draw a Polygon in Java Applet
13. AWT Hierarchy | AWT Package
14. Swing in Core Java