package normalcalc;
import java.applet.Applet;
import java.awt.Button;
import java.awt.Label;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/**
*
* @author Karthi
*/
public class Normalcalc extends Applet implements ActionListener
{
Label l1=new Label("A");
Label l2=new Label("B");
Label l3=new Label("Result");
TextField t1=new TextField(20);
TextField t2=new TextField(20);
TextField t3=new TextField(20);
Button b1=new Button(" + ");
Button b2=new Button(" - ");
Button b3=new Button(" * ");
Button b4=new Button(" / ");
public void init()
{
add(l1);
add(t1);
add(l2);
add(t2);
add(l3);
add(t3);
add(b1);
add(b2);
add(b3);
add(b4);
t1.addActionListener(this);
t2.addActionListener(this);
//t3.addActionListener(this);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
int a,b,c;
String str;
str=t1.getText();
a=Integer.parseInt(str);
str=t2.getText();
b=Integer.parseInt(str);
if(e.getSource()==b1)
{
c=a+b;
t3.setText(String.valueOf(c));
}
if(e.getSource()==b2)
{
c=a-b;
t3.setText(String.valueOf(c));
}
if(e.getSource()==b3)
{
c=a*b;
t3.setText(String.valueOf(c));
}
if(e.getSource()==b4)
{
c=a/b;
t3.setText(String.valueOf(c));
}
}
}