我得到 NullPointerException。这里有什么问题?
public class MainPanel extends JPanel {
private final int WIDTH = 600;
private final int HEIGHT = 400;
private InputMap imap = getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
private ActionMap amap;
public MainPanel() {
setPreferredSize(new Dimension(WIDTH, HEIGHT));
makeShortcut("UP", new AbstractAction() {
public void actionPerformed(ActionEvent ev) {
System.out.print("up");
}
});
}
public void makeShortcut(String keys, AbstractAction action) {
imap.put(KeyStroke.getKeyStroke(keys), "action"+keys);
amap.put("action"+keys, action);
}
}
您的帖子没有太多上下文来解释代码部分;请更清楚地解释您的情况。