title: HOw to move my bullet slowly in java?
body: <p>Hi I am developing a game that a fighter moves right and left and shoots. For the shooting part, I tried to use a for loop to slow the speed down and user can see the bullet. But it wasn't enough. I used sleep too but not a good answer. Now I have no idea what to do. 
  Here is my paintComponent calss:</p>
  
  <pre><code>package game;
  
  import java.awt.Color;
  import java.awt.Graphics;
  import java.awt.Graphics2D;
  import java.awt.event.KeyEvent;
  import java.awt.event.KeyListener;
  import java.awt.geom.Rectangle2D;
  import java.awt.image.BufferedImage;
  import java.io.File;
  import java.io.IOException;
  import java.util.ArrayList;
  import javax.imageio.ImageIO;
  import javax.swing.JPanel;
  
  
  
  public class PaintComponent extends JPanel implements KeyListener {
      int dx = 200-15;
      int dy = 450;
      int my = 450;
  
      ArrayList&lt;Bullet&gt; bullets = new ArrayList&lt;&gt;();
      public Rectangle2D rec =new Rectangle2D.Double(dx , dy, 30, 10);
      Rectangle2D recB = new Rectangle2D.Double(dx+13 , my, 6, 6);
  
  //    public Polygon pol = new Polygon
      private BufferedImage imageBg, imageFi, imageBu;
  
  
      public PaintComponent() {
          this.addKeyListener(this);
          this.setFocusable(true);
          this.setBackground(Color.white);
  
          try {                
            imageBg = ImageIO.read(new File("C:\\Java\\NetbeansProjects\\Game\\bg.jpg"));
            imageBu = ImageIO.read(new File("C:\\Java\\NetbeansProjects\\Game\\bul.png"));
            imageFi = ImageIO.read(new File("C:\\Java\\NetbeansProjects\\Game\\fi.png"));
         } catch (IOException ex) {
              System.out.println("No background image is available!");
         }
      }
  
      public void shoot(){
          if(bullets != null){
              for(int i=0; i&lt;bullets.size(); i++){
                  for(int j=0; j&lt;200; j++){
                      bullets.get(i).setdy(my-j);
                  }
                  System.out.println(bullets.get(i).getdy());
              }
          }
      }
      public void moveRec(KeyEvent evt){
          switch(evt.getKeyCode()){
              case KeyEvent.VK_LEFT:
              dx -= 5;
              rec.setRect(dx, dy, 30, 10);
              recB.setRect(dx+13, dy, 6, 6);
              repaint();
              break;
          case KeyEvent.VK_RIGHT:
              dx += 5;
              rec.setRect(dx, dy, 30, 10);
              recB.setRect(dx+13, dy, 6, 6);
              repaint();
              break;
          case KeyEvent.VK_SPACE:
              Bullet b = new Bullet(dx, dy);
              bullets.add(b);
              shoot();
              break;
  
      }
  }
  
          @Override
          public void paintComponent(Graphics grphcs)
              {super.paintComponent(grphcs);
              Graphics2D gr = (Graphics2D) grphcs;
                  int X = (int) rec.getCenterX();
                  int Y = (int) rec.getCenterY();
                  gr.drawImage(imageBg, 0, 0, null);
                  gr.drawImage(imageFi, X-50, Y-75, null);
                  gr.setColor(Color.GRAY);
                  if(bullets != null){
                      for(int i=0;i&lt;bullets.size();i++){
                     gr.drawImage(imageBu, null, bullets.get(i).getdx(), bullets.get(i).getdy());
                     repaint();
                      }
                  }
                  gr.draw(recB);
              }
  
      @Override
      public void keyTyped(KeyEvent e) {
      }
      @Override
      public void keyPressed(KeyEvent e) 
      {moveRec(e);}
      @Override
      public void keyReleased(KeyEvent e) 
      {}
  }
  </code></pre>
  
  <p>and this is my bullet calss:</p>
  
  <pre><code>package game;
  
  public class Bullet {
      private int x, y, newy;
  
      public Bullet(int x, int y){
          this.x = x;
          this.y = y;
      }
  
      public int getdy(){
          return y;
      }
      public void setdy(int newy){
          y = newy;
      }
      public int getdx(){
          return x;
      }
  }
  </code></pre>