Diferencia entre KeyBindings y KeyListeners
¿Cuál es el punto de KeyBindings si pudiera hacer:
// Imports
public void Test {
JButton button1;
JButton button2;
JButton button3;
...
Test() {
button1 = new JButton();
button1.addKeyListener(this);
button2 = new JButton();
button2.addKeyListener(this);
button3 = new JButton();
button3.addKeyListener(this);
...
}
public void keyPressed(KeyEvent e) {
}
public void keyReleased(KeyEvent e) {
}
public void keyTyped(KeyEvent e) {
Object src = e.getSource();
if (src == button1) {
...
}
else if (src == button2) {
...
}
else if (src == button3) {
...
}
...
}
}
Digamos que tengodiez botones. Luego, si usa KeyBindings, tendrá que hacer una combinación de teclas para cada botón. ¿No es el ejemplo que mostré más eficiente? Por qué no?