package Utilities;//======================================================================//  PROJECT:            _programming.java_//  FILE:               Keypad.java//  PURPOSE:            Chapter 7 demo program, Keypad class//  VERSION:            1.0//  TARGET:             Java v1.1//  UPDATE HISTORY:     1.0    11/2/98     //======================================================================//------------------------------ IMPORTS -------------------------------import java.awt.*;import java.awt.event.*;//=========================== Keypad CLASS =============================/** * A Keypad object contains eleven buttons, representing * the digits 0 through 9 and the decimal point.  When * another class uses a Keypad object, an appropriate * ActionListener must be provided to the Keypad * constructor, by calling addActionListener(). * <BR> * We have to invent our own method for registering * the buttons, since the Panel class doesn't have an * addActionListener() method. */public class Keypad extends Panel{    private Button  b0, b1, b2, b3, b4, b5, b6,                    b7, b8, b9, bPoint;        /**     * Construct a Keypad object by laying out     * the buttons.     */    public Keypad()    {        setLayout(new GridLayout(4, 1, 4, 4));                // Top row        Panel p1 = new Panel();        p1.setLayout(new GridLayout(1, 3, 4, 4));        b7 = new Button("7");        p1.add(b7);        b8 = new Button("8");        p1.add(b8);        b9 = new Button("9");        p1.add(b9);        add(p1);                // Second row        Panel p2 = new Panel();        p2.setLayout(new GridLayout(1, 3, 4, 4));        b4 = new Button("4");        p2.add(b4);        b5 = new Button("5");        p2.add(b5);        b6 = new Button("6");        p2.add(b6);        add(p2);                // Third row        Panel p3 = new Panel();        p3.setLayout(new GridLayout(1, 3, 4, 4));        b1 = new Button("1");        p3.add(b1);        b2 = new Button("2");        p3.add(b2);        b3 = new Button("3");        p3.add(b3);        add(p3);                // Bottom row        Panel p4 = new Panel();        p4.setLayout(new BorderLayout(7, 4));        b0 = new Button("0");        p4.add("Center", b0);        bPoint = new Button(".");        p4.add("East", bPoint);        add(p4);    }        /**     * Register all of the buttons as sources for     * ActionEvents to be handled by the ActionListener     * provided in the argument.     */    public void addActionListener(ActionListener listener)    {        b0.addActionListener(listener);        b1.addActionListener(listener);        b2.addActionListener(listener);        b3.addActionListener(listener);        b4.addActionListener(listener);        b5.addActionListener(listener);        b6.addActionListener(listener);        b7.addActionListener(listener);        b8.addActionListener(listener);        b9.addActionListener(listener);        bPoint.addActionListener(listener);    }}