Java Reference
In-Depth Information
67 Adds a button to the button panel.
68 @param label the button label
69 */
70 private void addButton( final String label)
71 {
72 class DigitButtonListener implements
ActionListener
73 {
74 public void
actionPerformed(ActionEvent event)
75 {
76
77 // Don't add two decimal points
78 if (label.equals( Ð.Ñ )
79 &&
display.getText().indexOf( Ð.Ñ ) != -1 )
80 return;
81
82 // Append label text to button
83 display.setText(display.getText()
+ label);
84 }
85 }
86
87 JButton button = new JButton (label);
88 buttonPanel.add(button);
89 ActionListener listener = new
DigitButtonListener();
90 button.addActionListener(listener);
91 }
92
93 /**
94 Gets the value that the user entered.
95 @return the value in the text field of the keypad
96 */
97 public double getValue()
98 {
99 return
Double.parseDouble(display.getText());
100 }
101
102 /**
Search WWH ::




Custom Search