Example of InputMap class of java:
Code:
import javax.swing.InputMap;
public class JMapMain {
public static void main(String[] argbv) {
InputMap im01 = new JTextArea().getInputMap(JComponent.WHEN_FOCUSED);
im01.put(KeyStroke.getKeyStroke("F2"), "actionNam01e");
ActionMap am01 = new JTextArea().getActionMap();
am01.put("actionNam01e", new AbstractAction("actionNam01e") {
public void actionPerformed(ActionEvent evt) {
System.out.println((JTextComponent) evt.getSource());
} };
im01.put(KeyStroke.getKeyStroke("F3"), "actionNam01e2");
am01.put("actionNam01e2", new AbstractAction("actionNam01e2") {
public void actionPerformed(ActionEvent evt) {
System.out.println((JTextComponent) evt.getSource());
} };
JButton component01 = new JButton("button 1");
JButton component02 = new JButton("button 2");
component01.setInputMap(JComponent.WHEN_FOCUSED, im01);
component02.setInputMap(JComponent.WHEN_FOCUSED, im01);
component01.setActionMap(am01);
component02.setActionMap(am01);
}
}
Bookmarks