Я пытаюсь сделать очень простую вещь: вызвать действие, когда пользователь нажимает на клавишу клавиатуры
клавиши, которые я хотел бы отобразить:
- key +
- key -
- key delete
- ctrl + c
ctrl + v
открытый класс keytestmain extendsАпплет {
//Called when this applet is loaded into the browser.
public void init() {
//Execute a job on the event-dispatching thread; creating this applet's GUI.
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
JLabel lbl = new JLabel("Hello World");
add(lbl);
JPanel p = new JPanel();
p.setBackground(Color.green);
p.setMinimumSize(new Dimension(100,100));
p.setPreferredSize(new Dimension(100,100));
p.setMaximumSize(new Dimension(100,100));
InputMap inputMap = new InputMap();
// Add a KeyStroke
inputMap.put(KeyStroke.getKeyStroke("SPACE"), "actionName");
inputMap.setParent(p.getInputMap(JComponent.WHEN_FOCUSED));
p.setInputMap(JComponent.WHEN_FOCUSED, inputMap);
add(p);
}
});
} catch (Exception e) {
System.err.println("createGUI didn't complete successfully");
}
}
}
но ничего не работает
Есть идеи?