I have some code that I need to modify. In the code, the original author uses KeyStroke.getKeyStroke
to take user input. In this code, for example, he uses a
instead of left arrow.
I want to change this, but I don't know how.
Here is the original code:
registerKeyboardAction(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
tick(RIGHT);
}
}, "right", KeyStroke.getKeyStroke('d'), WHEN_IN_FOCUSED_WINDOW
);
I have to change it to something like this, but when run, it doesn't work:
KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT);
KeyStroke.getKeyStroke("RIGHT");
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…