Java Reference
In-Depth Information
public void removeActionListener(ActionListener actionListener) {
actionListenerList = AWTEventMulticaster.remove(
actionListenerList, actionListener);
}
public boolean isFocusable() {
return true;
}
}
Figure 2-5 shows the component in use. The top portion of the figure is the component,
and the bottom is a text field. An ActionListener is registered with the KeyTextComponent that
updates the text field in order to display the text string for the key pressed.
Figure 2-5. Demonstrating the KeyTextComponent
The source code for the example shown in Figure 2-5 follows in Listing 2-5.
Listing 2-5. Sample Program with an AWTEventMulticaster Component
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class KeyTextTester {
public static void main(String args[]) {
Runnable runner = new Runnable() {
public void run() {
JFrame frame = new JFrame("Key Text Sample");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
KeyTextComponent keyTextComponent = new KeyTextComponent();
final JTextField textField = new JTextField();
ActionListener actionListener = new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
String keyText = actionEvent.getActionCommand();
textField.setText(keyText);
}
};
 
Search WWH ::




Custom Search