import java.io.*;
import java.lang.Math.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.Component.*;
public class Calculator extends Frame implements ActionListener, WindowListener
/* EQUAL
* POINT
* DECIMAL
* C
* MATH */
{
//1 Window
TextField Txwindow;
//29 Buttons
Button b1,b2,b3,b4,b5,b6,b7,b8,b9,b0; //10 Buttons on this Line
Button b10algo,blog,bealgo,bln; //4 Buttons on this Line
Button bpi,broot,bpower,be; //4 Buttons on this Line
Button bsin, bcos, btan, btrig; //4 Buttons on this Line
Button bclear,bpoint,bequal; //3 Buttons on this Line
Button badd,bsub,bmulti,bdivi; //4 Buttons on this Line
//5 Panels
Panel panelNorth,panelSouth,panelEast,panelWest,panelCenter;
int x;
String aux1;
String aux2, lastCommand;
String value, calcDisplay;
int op, counter=0;
boolean point=false;
double n1,n2,n3,n4,preAns,secVal;
double answer=0,ans;
public static void main(String[] args) throws IOException
{
Calculator form=new Calculator(); //Creates a specified class
form.setSize(400,600); //Establishes Size of Window
form.setTitle ("CASIO FX-Superb007"); //This is the Title
form.setVisible(true); //The Window will Become Visible
}
public Calculator() throws IOException {
//Layout Head
setLayout(new BorderLayout(1,1));//Head, Beginning
//Panel
panelNorth= new Panel(new FlowLayout());
panelSouth= new Panel(new GridLayout(1,1));
panelEast= new Panel(new GridLayout(4,1));
panelWest= new Panel(new GridLayout(5,1));
panelCenter= new Panel(new GridLayout(6,3));
//North Finished
Txwindow= new TextField(50);
Txwindow.setEditable(false);
panelNorth.add(Txwindow);
//South Finished
bequal= new Button("="); //Equal Button
panelSouth.add(bequal);
//listener
bequal.addActionListener(this);
//West Finished
b10algo= new Button("10^x"); //10^algo
blog= new Button("+/-"); //Log
bealgo= new Button("e^x"); //E^algo
bln= new Button("Ln"); //Ln
be= new Button("e"); //e
panelWest.add(b10algo);
panelWest.add(blog);
panelWest.add(bealgo);
panelWest.add(bln);
panelWest.add(be);
//listener
b10algo.addActionListener(this);
blog.addActionListener(this);
bealgo.addActionListener(this);
bln.addActionListener(this);
be.addActionListener(this);
//East Finished
badd= new Button ("+"); //Addition
bsub= new Button("-"); //Subtraction
bmulti= new Button("*"); //Multiplication
bdivi= new Button("/"); //Division
panelEast.add(badd);
panelEast.add(bsub);
panelEast.add(bmulti);
panelEast.add(bdivi);
//listener
badd.addActionListener(this);
bsub.addActionListener(this);
bmulti.addActionListener(this);
bdivi.addActionListener(this);
//Center Finished
b1= new Button("1"); //Number 1
b2= new Button("2"); //Number 2
b3= new Button("3"); //Number 3
b4= new Button("4"); //Number 4
b5= new Button("5"); //Number 5
b6= new Button("6"); //Number 6
b7= new Button("7"); //Number 7
b8= new Button("8"); //Number 8
b9= new Button("9"); //Number 9
b0= new Button("0"); //Number 0
bpi= new Button("Pi");//pi
bpower= new Button("Power"); //Power
broot= new Button("Root"); //Root
bsin= new Button("Sin"); //sin
bcos= new Button("Cos"); //cos
btan= new Button("Tan"); //tan
bPoint= new Button("."); //Point
bclear= new Button("C"); //clear
panelCenter.add(bpi);
panelCenter.add(bpower);
panelCenter.add(broot);
panelCenter.add(bsin);
panelCenter.add(bcos);
panelCenter.add(btan);
panelCenter.add(b1);
panelCenter.add(b2);
panelCenter.add(b3);
panelCenter.add(b4);
panelCenter.add(b5);
panelCenter.add(b6);
panelCenter.add(b7);
panelCenter.add(b8);
panelCenter.add(b9);
panelCenter.add(bpoint);
panelCenter.add(b0);
panelCenter.add(bclear);
//listener
bpi.addActionListener(this);
bpower.addActionListener(this);
broot.addActionListener(this);
bsin.addActionListener(this);
bcos.addActionListener(this);
btan.addActionListener(this);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
b6.addActionListener(this);
b7.addActionListener(this);
b8.addActionListener(this);
b9.addActionListener(this);
bpoint.addActionListener(this);
b0.addActionListener(this);
bclear.addActionListener(this);
panelCenter.repaint();
//Add to Panels, Border Layout
add(panelNorth, BorderLayout.NORTH);
add(panelSouth, BorderLayout.SOUTH);
add(panelEast, BorderLayout.EAST);
add(panelWest, BorderLayout.WEST);
add(panelCenter, BorderLayout.CENTER);
//This Adds a Listener to the Window
addWindowListener(this); }
public void repaint(Graphics g){
//The Color of this
g.setColor(Color.blue);
}
public void actionPerformed(ActionEvent e){
//input numbers
if(e.getSource() == b1){ aux1="1"; window=Txwindow.getText()+aux1; Txwindow.setText(value); }
if(e.getSource() == b2){ aux1="2"; window=Txwindow.getText()+aux1; Txwindow.setText(value); }
if(e.getSource() == b3){ aux1="3"; window=Txwindow.getText()+aux1; Txwindow.setText(value); }
if(e.getSource() == b4){ aux1="4"; window=Txwindow.getText()+aux1; Txwindow.setText(value); }
if(e.getSource() == b5){ aux1="5"; window=Txwindow.getText()+aux1; Txwindow.setText(value); }
if(e.getSource() == b6){ aux1="6"; window=Txwindow.getText()+aux1; Txwindow.setText(value); }
if(e.getSource() == b7){ aux1="7"; window=Txwindow.getText()+aux1; Txwindow.setText(value); }
if(e.getSource() == b8){ aux1="8"; window=Txwindow.getText()+aux1; Txwindow.setText(value); }
if(e.getSource() == b9){ aux1="9"; window=Txwindow.getText()+aux1; Txwindow.setText(value); }
if(e.getSource() == b0){ aux1="0"; window=Txwindow.getText()+aux1; Txwindow.setText(value); }
if(e.getSource() == bpoint&& point==false){ aux1="."; value=Txwindow.getText()+aux1; Txwindow.setText(value); point=true; }
//The Functions
if(e.getSource() == bpi){ Txwindow.setText(""+Math.PI); value=""; }
if(e.getSource() == be){ Txwindow.setText(""+Math.E); value=""; }
if(e.getSource() == bpower){
aux2=Txwindow.getText();
if(!aux2.equals("")){
preAns=Double.parseDouble(Txwindow.getText());
lastCommand="power";
Txwindow.setText("");}}
if(e.getSource() == broot){
aux2=Txwindow.getText();
if(!aux2.equals(""))
{n1=Double.parseDouble(Txwindow.getText());
Txwindow.setText(""+Math.sqrt(n1));
} }
if(e.getSource() == bsin){
aux2=Txwindow.getText();
if(!aux2.equals(""))
{n1=Double.parseDouble(Txwindow.getText());
Txwindow.setText(""+Math.sin(Math.toRadians(n1)));
}}
if(e.getSource() == bcos){
aux2=Txwindow.getText();
if(!aux2.equals(""))
{n1=Double.parseDouble(Txwindow.getText());
Txwindow.setText(""+Math.cos(Math.toRadians(n1)));
} }
if(e.getSource() == btan){
aux2=Txwindow.getText();
if(!aux2.equals(""))
{n1=Double.parseDouble(Txwindow.getText());
Txwindow.setText(""+Math.tan(Math.toRadians(n1)));
} }
if(e.getSource() == b10algo){
aux2=Txwindow.getText();
if(!aux2.equals(""))
{n1=Double.parseDouble(Txwindow.getText());
Txwindow.setText(""+Math.pow(10.0,n1));
} }
if(e.getSource() == blog){
aux2=Txwindow.getText();
if(!aux2.equals(""))
{n1=Double.parseDouble(Txwindow.getText());
n1=n1*(-1);
Txwindow.setText(""+n1);
} }
if(e.getSource() == bealgo){
aux2=Txwindow.getText();
if(!aux2.equals(""))
{n1=Double.parseDouble(Txwindow.getText());
Txwindow.setText(""+Math.pow(Math.E,n1));
} }
if(e.getSource() == bln){
aux2=Txwindow.getText();
if(!aux2.equals(""))
{n1=Double.parseDouble(Txwindow.getText());
Txwindow.setText(""+Math.log(n1));
} }
if(e.getSource() == badd){
aux2=Txwindow.getText();
if(!aux2.equals("")){
preRes=Double.parseDouble(Txwindow.getText());
lastCommand="+";
Txwindow.setText("");}
if(e.getSource() == broot){
aux2=Txwindow.getText();
if(!aux2.equals("")){
preRes=Double.parseDouble(Txwindow.getText());
lastCommand="-";
Txwindow.setText("");}
}
if(e.getSource() == bmulti){
aux2=Txwindow.getText();
if(!aux2.equals("")){
preRes=Double.parseDouble(Txwindow.getText());
lastCommand="*";
Txwindow.setText("");}}
if(e.getSource() == bdivi){
aux2=Txwindow.getText();
if(!aux2.equals("")){
preRes=Double.parseDouble(Txwindow.getText());
lastCommand="/";
Txwindow.setText("");}}
if(e.getSource() == bclear){ Txwindow.setText(""); }
if(e.getSource() == bequal){
Double secVal=Double.parseDouble(Txwindow.getText());
if(lastCommand.equals("+"))
ans=preAns+secVal;
else if(lastCommand.equals("-"))
ans=preAns-secVal;
else if(lastCommand.equals("*"))
ans=preAns*secVal;
else if (lastCommand.equals("/"))
ans=preAns/secVal;
else if (lastCommand.equals("power"));
ans=Math.pow(preAns,secVal);
Txwindow.setText(" "+ans);
lastCommand="=";
}}
public double calcoperations(int op, double aux2){
if(op==1)
{}
if(op==2)
{}
if(op==3)
{}
if(op==4)
{}
if(op==5)
{}
return ans; }
public void windowClosing(WindowEvent e){
System.exit(0);
}
public void windowActivated(WindowEvent e){
}
public void windowClosed(WindowEvent e){
}
public void windowDeactivated(WindowEvent e){
}
public void windowDeiconified(WindowEvent e){
}
public void windowIconified(WindowEvent e){
}
public void windowOpened(WindowEvent e){
}
}