S
Si
I use the code below to detect when a key is being pressed. Unfortunately it
only responds when the key is first pressed.
What I would like to do is detect when the key is initially pressed, and
when it is released.
How do I modify the code below to achieve this?
Thanks.
=============================
//below is in main application view constructor
contentPane.getInputMap(javax.swing.JComponent.WHEN_IN_FOCUSED_WINDOW).put(javax.swing.KeyStroke.getKeyStroke('a'),"a_pressed");
contentPane.getActionMap().put("a_pressed", new AbstractActionGB(gb));
//below is inner class in main application view
class AbstractActionGB extends javax.swing.AbstractAction {
model.GameBoard gb;
public AbstractActionGB(GameBoard gb) {
this.gb = gb;
}
public void actionPerformed(ActionEvent e)
{
System.out.println("A WAS PRESSED!!!");
gb.flipFlipper();
}
}
only responds when the key is first pressed.
What I would like to do is detect when the key is initially pressed, and
when it is released.
How do I modify the code below to achieve this?
Thanks.
=============================
//below is in main application view constructor
contentPane.getInputMap(javax.swing.JComponent.WHEN_IN_FOCUSED_WINDOW).put(javax.swing.KeyStroke.getKeyStroke('a'),"a_pressed");
contentPane.getActionMap().put("a_pressed", new AbstractActionGB(gb));
//below is inner class in main application view
class AbstractActionGB extends javax.swing.AbstractAction {
model.GameBoard gb;
public AbstractActionGB(GameBoard gb) {
this.gb = gb;
}
public void actionPerformed(ActionEvent e)
{
System.out.println("A WAS PRESSED!!!");
gb.flipFlipper();
}
}