import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class Compute extends java.applet.Applet implements ActionListener{
char sol;
String s1, s2;
double d1,d2,d3;
String str=" ";
Label lbl=new Label();
Button one, two, three, four, five, six, seven, eight, nine, zero, dot, plus, min, div, mult, eq;
Button cmd= new Button("Clear");
public void init() {
setLayout(null);
setBackground(Color.BLACK);
lbl=new Label();
lbl.setBackground(Color.GRAY);
add(lbl);
lbl.setBounds(20, 20, 100, 25);
one=new Button("1");
add(one);
one.setBounds(20, 50, 25, 25);
one.addActionListener(this);
two=new Button("2");
add(two);
two.setBounds(45, 50, 25, 25);
two.addActionListener(this);
three=new Button("3");
add(three);
three.setBounds(70, 50, 25, 25);
three.addActionListener(this);
four=new Button("4");
add(four);
four.setBounds(20, 75, 25, 25);
four.addActionListener(this);
five=new Button("5");
add(five);
five.setBounds(45, 75, 25, 25);
five.addActionListener(this);
six=new Button("6");
add(six);
six.setBounds(70, 75, 25, 25);
six.addActionListener(this);
seven=new Button("7");
add(seven);
seven.setBounds(20, 100, 25, 25);
seven.addActionListener(this);
eight=new Button("8");
add(eight);
eight.setBounds(45, 100, 25, 25);
eight.addActionListener(this);
nine=new Button("9");
add(nine);
nine.setBounds(70, 100, 25, 25);
nine.addActionListener(this);
zero=new Button("0");
add(zero);
zero.setBounds(20, 125, 25, 25);
zero.addActionListener(this);
plus=new Button("+");
add(plus);
plus.setBounds(95, 50, 25, 25);
plus.addActionListener(this);
min=new Button("-");
add(min);
min.setBounds(95, 75, 25, 25);
min.addActionListener(this);
mult=new Button("*");
add(mult);
mult.setBounds(95, 100, 25, 25);
mult.addActionListener(this);
div=new Button("/");
add(div);
div.setBounds(95, 125, 25, 25);
div.addActionListener(this);
dot=new Button(".");
add(dot);
dot.setBounds(45, 125, 25, 25);
dot.addActionListener(this);
eq=new Button("=");
add(eq);
eq.setBounds(70, 125, 25, 25);
eq.addActionListener(this);
add(cmd);
cmd.setBounds(20, 150, 50, 20);
cmd.addActionListener(this);
}
public void paint(Graphics g) {
}
public void actionPerformed(ActionEvent x)
{
if(x.getSource()==one)
str=str+"1";
lbl.setText(str);
if(x.getSource()==two)
str=str+"2";
lbl.setText(str);
if(x.getSource()==three)
str=str+"3";
lbl.setText(str);
if(x.getSource()==zero)
str=str+"0";
lbl.setText(str);
if(x.getSource()==four)
str=str+"4";
lbl.setText(str);
if(x.getSource()==five)
str=str+"5";
lbl.setText(str);
if(x.getSource()==six)
str=str+"6";
lbl.setText(str);
if(x.getSource()==seven)
str=str+"7";
lbl.setText(str);
if(x.getSource()==eight)
str=str+"8";
lbl.setText(str);
if(x.getSource()==nine)
str=str+"9";
lbl.setText(str);
if(x.getSource()==dot)
str=str+".";
lbl.setText(str);
if(x.getSource()==plus)
s1=lbl.getText();
str=" ";
lbl.setText(str);
d1=Double.parseDouble(s1.trim());
sol='+';
if(x.getSource()==min)
s1=lbl.getText();
str=" ";
lbl.setText(str);
d1=Double.parseDouble(s1.trim());
sol='-';
if(x.getSource()==mult)
s1=lbl.getText();
str=" ";
lbl.setText(str);
d1=Double.parseDouble(s1.trim());
sol='*';
if(x.getSource()==div)
s1=lbl.getText();
str=" ";
lbl.setText(str);
d1=Double.parseDouble(s1.trim());
sol='/';
if(x.getSource()==eq)
{
s2=lbl.getText();
d2=Double.parseDouble(s2.trim());
String s3=" ";
switch(sol)
{
case '+':
d3=d1+d2;
break;
case '-':
d3=d1-d2;
break;
case '*':
d3=d1*d2;
case '/':
d3=d1/d2;
break;
}
s3=Double.toString(d3);
lbl.setText(s3);
if(x.getSource()==cmd)
{
s1=" ";
s2=" ";
d1=0;
d2=0;
d3=0;
lbl.setText(" ");
}
}//end of eq
}//end of actionPerformed
}