You are on page 1of 1

//program for Button Event handling

import java.awt.*;
import java.awt.event.*;
public class demo extends Frame implements ActionListener
{
TextField t1,t2,t3;
Button b1;
demo()
{
setLayout(new FlowLayout());
Label l1=new Label("number1");
Label l2=new Label("number2");
Label l3=new Label("answer");
t1=new TextField(20);
t2=new TextField(20);
t3=new TextField(20);
b1 =new Button("ADDITION");
b1.addActionListener(this);
add(l1);
add(t1);
add(l2);
add(t2);
add(l3);
add(t3);
add(b1);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)
{
String s1=t1.getText();
String s2=t2.getText();
int n1=Integer.parseInt(s1);
int n2=Integer.parseInt(s2);
int n3=n1+n2;
t3.setText(n3+"");

}
public static void main(String args[])
{
demo d=new demo();
d.setSize(300,300);
d.setVisible(true);

You might also like