UNB/ CS/ David Bremner/ teaching/ java/ RPNCalc2.java
import javax.swing.JLabel;
public class RPNCalc2 extends DBFrame implements KeyPadClient, 
                                                 HistoryPaneClient{

    private JLabel resultLabel=new JLabel("results");

    private PromptField input;
    private RPNStack stack=new RPNStack();
    
    private HistoryPane results;

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

    public void mouseClickCallback(String text){
        input.setText(text);
    }

    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);
        results.addElement(result);
        input.setText("");
    }
    public RPNCalc2(){
        results=new HistoryPane();
        results.addClient(this);

        
        getContentPane().add(resultLabel);
        getContentPane().add(results);

        input=new PromptField("input",20);
        getContentPane().add(input);

        KeyPad k=new KeyPad(labels,this);
        getContentPane().add(k);
        setVisible(true);
    }
    public static void main(String [] args){
        RPNCalc2 r=new RPNCalc2();
    }
}
//