need help with actionmap and inputmap for jdialog
hi, I want to do the same as this thread:
http://forum.java.sun.com/thread.jspa?threadID=446614&messageID=2026106
But nothing happens when I press my left and right buttons in the Jdialog. I'm not sure what is wrong with my code. Any help appreciated!
This is in the constructor of the JDialog:
this.setFocusable(true);
ActionMap am = getRootPane().getActionMap();
InputMap im = getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
Object windowLeftKey =new Object();
Object windowRightKey =new Object();
KeyStroke windowLeftStroke = KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0);
KeyStroke windowRightStroke = KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0);
Action windowLeftAction =new AbstractAction(){
publicvoid actionPerformed(ActionEvent e){
setAlphaWinner();
}
};
Action windowRightAction =new AbstractAction(){
publicvoid actionPerformed(ActionEvent e){
setBetaWinner();
}
};
am.put(windowLeftKey, windowLeftAction);
im.put(windowLeftStroke, windowLeftKey);
am.put(windowRightKey, windowRightAction);
im.put(windowRightStroke, windowRightKey);

