I have a class extending jframe with a key binding mapped to an invisible button that does stuff. When I press the key on the keyboard, it executes the command of the button. However, if the user holds the button down, it will execute the command like a hundred times per second, crashing the program. How do I prevent this so that the command only executes... let's say... once per second when the key is pressed down?
Code snippets are as follows:
JButton fire = new JButton("");
KeyStroke spaceBar = KeyStroke.getKeyStroke("SPACE");
FireCommand fc = new FireCommand();
this.fire.setAction(fc);
imap.put(SpaceBar,"space");
amap.put("space",fc);