UNB/ CS/ David Bremner/ teaching/ java/ NumberPad.java
import javax.swing.JPanel;
import javax.swing.BoxLayout;
import javax.swing.JTextField;
import java.math.BigDecimal;
public class NumberPad extends JPanel implements KeyPadClient{
    private NumberPadClient client;
    private KeyPad keypad;
    private JTextField input;

    public void setClient(NumberPadClient argClient){
        client=argClient;
    }
    public void keypressCallback(String text){
        if (text.length()==1 && '0' <= text.charAt(0) && 
            text.charAt(0) <= '9' || text.charAt(0)=='.'){           
            try{
                String newVal=(input.getText() + text);
                BigDecimal test=new BigDecimal(newVal);
                input.setText(newVal);
            }
            catch (NumberFormatException e){
                // ignore that key
            }
        } else{
            client.numberPadCallback(text);
        }

    }
    

    NumberPad(String[][] labels){
        this.setLayout(new BoxLayout(this,BoxLayout.Y_AXIS));
        input= new JTextField(10);
        this.add(input);
        keypad=new KeyPad(labels);
        keypad.setClient(this);
        this.add(keypad);
    }
        
}
//