所以我不能同时使用两把钥匙,我希望这能发生。
我的代码在这里:
https://pastebin.com/dqcs9dvi
如果您尝试同时移动它们,则只有一个会移动,或者没有一个会移动。我认为这与这里的代码有关:
public KeyBidings(){
Action upAction = new AbstractAction(){
public void actionPerformed(ActionEvent e) {
y2 -=10;
}
};
Action downAction = new AbstractAction(){
public void actionPerformed(ActionEvent e) {
y2 +=10;
}
};
Action wAction = new AbstractAction(){
public void actionPerformed(ActionEvent e) {
y -=10;
}
};
Action sAction = new AbstractAction(){
public void actionPerformed(ActionEvent e) {
y +=10;
}
};
drawPanel.repaint();
InputMap inputMap = drawPanel.getInputMap(JPanel.WHEN_IN_FOCUSED_WINDOW);
ActionMap actionMap = drawPanel.getActionMap();
inputMap.put(KeyStroke.getKeyStroke("DOWN"), "downAction");
actionMap.put("downAction", downAction);
inputMap.put(KeyStroke.getKeyStroke("UP"), "upAction");
actionMap.put("upAction", upAction);
inputMap.put(KeyStroke.getKeyStroke("S"), "sAction");
actionMap.put("sAction", sAction);
inputMap.put(KeyStroke.getKeyStroke("W"), "wAction");
actionMap.put("wAction", wAction);
暂无答案!
目前还没有任何答案,快来回答吧!