shooting delays and movement issues

Good evening gamers!
I have 2 problems:
Problem 1:
when I hold press the space key to shoot, 2 things happen:
- at first it shoot one bullet and then it stops for about a second and then it continue shooting the other bullets
- while I’m shooting the bullets if I pressed the down or up keys to move the spaceship it stops shooting.

problem 2:
if I pressed the right arrow key to move the spaceship and then I quickly pressed the left arrow key the spaceship stops
for about a second and it continue moving to the left.

how can I solve these 2 problems ? what I want is this:

  1. I want the moment I press the space key to shoot, it start shooting immediately bullet after the other.
  2. I want to be able to shoot while I’m moving the ship.
  3. I want to be able to move smoothly right and left without any delays.

here’s my code:


public void keyPressed(KeyEvent e) {
        int key = e.getKeyCode();

        if (key == KeyEvent.VK_SPACE) {
            fire();
        }

        if (key == KeyEvent.VK_DOWN) {
            dy = 2;
        }

        if (key == KeyEvent.VK_UP) {
            dy = -2;
        }

        if (key == KeyEvent.VK_RIGHT) {
            dx = 2;
        }

        if (key == KeyEvent.VK_LEFT) {
            dx = -2;
        }
    }

    public void keyReleased(KeyEvent e) {
        int key = e.getKeyCode();

        if (key == KeyEvent.VK_DOWN) {
            dy = 0;
        }

        if (key == KeyEvent.VK_UP) {
            dy = 0;
        }

        if (key == KeyEvent.VK_RIGHT) {
            dx = 0;
        }

        if (key == KeyEvent.VK_LEFT) {
            dx = 0;
        }
    }

And here’s a link to download the game in a jar extension + the source code :
https://www.mediafire.com/?ebc5okuk2uk0g05