/**
 * Class Calc - write a description of the class here
 * 
 * @author: Kleanthis Thramboulidis
 * date: 
 */
import java.util.*;

import java.awt.*;
import java.awt.event.*;

public class Calc{
	static Stack st;
	static Adder ad;
	static Subtracter sub;
	static Equals eq;
	static Operand op;
	static CalculatorGui cg;
	
	public static void main(String[] argv){

		st = new Stack();
		ad = new Adder(st);
		sub = new Subtracter(st);
		eq = new Equals(st);
		op = new Operand(st);
		cg=new CalculatorGui(op);
		op.setCalculatorGui(cg);
		eq.setCalculatorGui(cg);
      }
}		


abstract class Operator implements ActionListener{
	Stack st;
	public Operator(Stack st) {
		this.st = st;
		}
	
	public abstract void operate();
	
		public void actionPerformed(ActionEvent pushingButton){ 
  		this.operate();
     	}
	}
	
class Adder extends Operator {
	public Adder(Stack st) {
		super(st);
		}
	
	public void operate(){	
		Double d = new Double(((Double)st.pop()).doubleValue() +
				       ((Double)st.pop()).doubleValue());

		st.push(d);
		}
	}

class Subtracter extends Operator {
	public Subtracter(Stack st) {
		super(st);
		}
	

	public void operate(){	
		Double d2 = (Double)st.pop();
		Double d = new Double(((Double)st.pop()).doubleValue() -
					d2.doubleValue());
		st.push(d);
		}
	}

/*
class Multiplier extends Operator {
	public void operate(){	
		Double d = new Double(((Double)Calc.s.pop()).doubleValue() *
				       ((Double)Calc.s.pop()).doubleValue());

		Calc.s.push(d);
		}
	}

class Divider extends Operator {
	public void operate(){	
		Double d2 = (Double)Calc.s.pop();
		Double d = new Double(((Double)Calc.s.pop()).doubleValue() /
					d2.doubleValue());
		Calc.s.push(d);
		}
	}
	*/
	
class Equals extends Operator /* implements ActionListener */{
	public CalculatorGui cg;
	
	public Equals(Stack st) {
		super(st);
		}
	
	public void setCalculatorGui(CalculatorGui cg){
		this.cg =cg;
		}
	
/*	public void actionPerformed(ActionEvent pushingButton){ 
   	this.operate();
   	}
*/   
	public void operate(){
		cg.display.setText(String.valueOf( ((Double)(st.pop())).doubleValue()));
		}
	}
