import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class newcalc extends Applet implements ActionListener{

TextField total;
TextField number;
Label totalL;
Label numberL;
Button subtract;
Button add2;
Button divide;
Button multiply;


public void init(){

setLayout(new GridLayout(4,2));
totalL = new Label("Total");
add(totalL);
total = new TextField(25);
add(total);
numberL = new Label("Number");
add(numberL);
number = new TextField(25);
add(number);
add2 = new Button("Add");
add2.addActionListener(this);
add(add2);
divide = new Button("Divide");
divide.addActionListener(this);
add(divide);
subtract = new Button("Subtract");
subtract.addActionListener(this);
add(subtract);
multiply = new Button("Multiply");
multiply.addActionListener(this);
add(multiply);
total.setText(String.valueOf(0));


}

public void actionPerformed(ActionEvent e){
double n;
double t;
double tot=0.0;

Button b = (Button)e.getSource();
if(b.equals(add2)){
n=Double.parseDouble(number.getText());
t=Double.parseDouble(total.getText());
tot = (n+t);
total.setText(String.valueOf(tot));
}
if(b.equals(subtract)){
n=Double.parseDouble(number.getText());
t=Double.parseDouble(total.getText());
tot = (t-n);
total.setText(String.valueOf(tot));
}
if(b.equals(divide)){
n=Double.parseDouble(number.getText());
t=Double.parseDouble(total.getText());
tot = (t/n);
total.setText(String.valueOf(tot));
}
if(b.equals(multiply)){
n=Double.parseDouble(number.getText());
t=Double.parseDouble(total.getText());
tot = (t*n);
total.setText(String.valueOf(tot));
}
}
}