package graphics; import java.awt.*; import java.awt.event.*; import javax.swing.*; public class TelephoneKeypadPanel extends JPanel { public TelephoneKeypadPanel() { setLayout(new GridLayout(4, 3)); makeButton("1", 1); makeButton("2 - abc", 2); makeButton("3 - def", 3); makeButton("4 - ghi", 4); makeButton("5 - jkl", 5); makeButton("6 - mno", 6); makeButton("7 - pqrs", 7); makeButton("8 - tuv", 8); makeButton("9 - wxyz", 9); makeButton("*", 42); makeButton("O - oper", 0); makeButton("#", 35); } private void makeButton(String label, int val) { JButton button = new JButton(label); button.addActionListener(new TelephoneButtonListener(val)); add(button); } private class TelephoneButtonListener implements ActionListener { private int value; public TelephoneButtonListener(int val) { value = val; } public void actionPerformed(ActionEvent event) { System.out.print(" " + value); } } }