I have updated the code, keyRepeated is still not being called
Code:
public void keyReleased()
{
buttonPressed = false;
repaint();
}
public void keyRepeated(int keyCode) //activates when the user repeats any button
{
try
{
buttonPressed = true;
eventType = "repeated";
this.keyCode = keyCode;
if (hasRepeatEvents() && buttonPressed == true)
{
keyPressed(keyCode);
repaint();
}
}
catch(Exception e)
{
System.out.println("Sprite Control Class : keyRepeated :" + e);
}
}
public void keyPressed(int keyCode) // this function is activited when the user hits a button on the keypad
{
try
{
eventType = "pressed"; // set event type
buttonPressed = true;
this.keyCode = keyCode; // set keycode
if( (50 == keyCode || 52 == keyCode || 54 == keyCode || 56 == keyCode) &&running == true && buttonPressed == true)
{
PlayerShip1.moveShip(keyCode); // if the keycode is 50 or 52 or 54 or 56 and game is running
repaint(); // call the player ship class to update and repaint
}
if (53 == keyCode && running == true && buttonPressed == true) // if the keycode is 53 and game is running
{
shipPositionX = PlayerShip1.getPositionX(); // set positions
shipPositionY = PlayerShip1.getPositionY();
int num1 = playerImage.getWidth(); // set width of image
PlayerShoot1.Shoot((num1 + shipPositionX), (shipPositionY+5), 0); // call player shoot to add shot at the positions and also the bullet type
repaint();
}
if (51 == keyCode && running == true)
{
shipPositionX = PlayerShip1.getPositionX();
shipPositionY = PlayerShip1.getPositionY(); // same as last but bullet type
int num1 = playerImage.getWidth(); // is 1 for missile
PlayerShoot1.Shoot(num1 + shipPositionX, shipPositionY, 1);
repaint();
}
else if(keyCode == 55)
{
keyReleased();
}
}
catch(Exception e)
{
System.out.println("Sprite Control Class : keypressed :" + e);
}
}