UNB/ CS/ David Bremner/ teaching/ java/ RPNCalc.java
import javax.swing.JTextField;
public class RPNCalc extends DBFrame implements KeyPadClient{

    private PromptField input,display;
    private RPNStack stack=new RPNStack();

    private final String labels[][]=
            { {"7","8","9"}, 
              {"4","5","6"},
              {"1","2","3"},
              {"0",".", "Enter"},
              {"+","-","*"},
              {"/","clear","quit" }};


    public void keypressCallback(String text){
        if (text.equals("clear")){
            input.setText("");
            return;
        }
        if (text.equals("quit")){
            System.exit(0);
        }
            
        if ('0' <= text.charAt(0) && 
            text.charAt(0) <= '9' || text.charAt(0)=='.'){           
            input.setText(input.getText() + text);
        } else{
            process(text);
        }
    }

    private void process(String text){
        String result,operand;
            
        operand=input.getText();
        if (operand.equals(""))
            operand=(String)stack.top();
        
        stack.push(operand);
        result=stack.process(text);
        display.setText(result);
        input.setText("");
    }
    public RPNCalc(){
        super(400,300);

        display=new PromptField("result",20);
        display.setEditable(false);
        input=new PromptField("input",20);
        this.getContentPane().add(display);
        
        this.getContentPane().add(input);
        KeyPad k=new KeyPad(labels,this);
        this.getContentPane().add(k);
        this.setVisible(true);
    }
    public static void main(String [] args){
        RPNCalc r=new RPNCalc();
    }
}
//