title: Smooth fast move and repaint()
body: <p>I'm writing easy space invaders and have a problem with moving ship. Basically I change position of ship and then <code>repaint()</code>. If the change is big it is more like jumping than moving. If the change is small animation is smoother but getting slower. Is there any solution?</p>
  
  <p>I'm drawing on JPanel and using <code>paintComponent()</code>. </p>
  
  <p>@edit: I don't really understand how my pc can display normal(new) games smoothly and with simple drawing image has low frame rate. It is why i thought it was software problem rather than hardware. So maybe i do something what affects frame rate.</p>
  
  <p>@edit: Ok, pasting some code, but be understanding - I started with java and generally programming graphics about 2 weeks ago. </p>
  
  <pre><code>    package pl.spaceInvaders;
      import java.awt.Color;
  import java.awt.Graphics;
  import java.awt.Graphics2D;
  import java.awt.Image;
  import java.awt.Insets;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import java.awt.event.KeyEvent;
  import java.awt.event.KeyListener;
  
  import javax.swing.JPanel;
  import javax.swing.Timer;
  
  class GamePanel extends JPanel{
  SpaceInvadersMain sim;
  private Image dbImage; 
  private Graphics dbg; 
  int moveDistHor=0;
  int moveDistVer=0;
  int shipMove=0;
  int dir=1;
  
  GamePanel(SpaceInvadersMain sim){
      this.sim=sim;
      setFocusable(true);
      moveMonsters();
      MyKeyListener mkl = new MyKeyListener();
      addKeyListener(mkl);
      Timer t = new Timer(500, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if(moveDistHor&lt;304){moveDistHor+=16*dir;}
                if(moveDistHor==304 || moveDistHor==0){dir*=-1;moveDistHor+=16*dir;moveDistVer+=16;}
                moveMonsters();
                moveProjectiles();
                detectColissions();
                repaint();
            }
         });
      t.start();
  }
  @Override
  public void paintComponent(Graphics g){
      super.paintComponent(g);
      setBackground(Color.white);
      Graphics2D g2 = (Graphics2D)g;
      Insets insets = getInsets();
      g2.translate(insets.left, insets.top);
      // drawing monsters
      for(int i=0;i&lt;SpaceInvadersMain.M_WIDTH;i++){
          for(int j=0;j&lt;SpaceInvadersMain.M_HIGHT;j++){
              if(sim.monsters[i][j].ifExists()){
              if((moveDistHor+moveDistVer)%32==0) 
                  g2.drawImage(sim.monsters[i][j].img, sim.monsters[i][j].posX, sim.monsters[i][j].posY, 32, 32, null);
              else 
                  g2.drawImage(sim.monsters[i][j].img2, sim.monsters[i][j].posX, sim.monsters[i][j].posY, 32, 32, null);
              }}
      }
      //drawing ship
      if(sim.ship.exists()) g2.drawImage(sim.ship.img, sim.ship.getPosX(), sim.ship.getPosY(),32,32,null);
  }
  protected void detectColissions() {
      // TODO Auto-generated method stub
  
  }
  protected void moveProjectiles() {
      // TODO Auto-generated method stub
  
  }
  protected void moveShip() {
      if(sim.ship.posX+shipMove&gt;0 &amp;&amp; sim.ship.posX+shipMove&lt;750) {
          sim.ship.posX+=shipMove;
          shipMove=0;
      }
  
  }
  protected void moveMonsters(){
      for(int i=0;i&lt;SpaceInvadersMain.M_WIDTH;i++){
          for(int j=0;j&lt;SpaceInvadersMain.M_HIGHT;j++){
              if(sim.monsters[i][j].ifExists()){
                   sim.monsters[i][j].posX=10+i*48+moveDistHor;
                   sim.monsters[i][j].posY=10+j*48+moveDistVer;
  
              }}
      }
  }
  private class MyKeyListener implements KeyListener{
  
      @Override
      public void keyPressed(KeyEvent e) {
          switch(e.getKeyCode()){
          case KeyEvent.VK_LEFT:
              //System.out.println("Arrow left caught");
              shipMove=-10;
              break;
          case KeyEvent.VK_RIGHT:
              //System.out.println("Arrow right caught");
              shipMove=10;
              break;
          }
          moveShip();
          repaint();
      }
  
      @Override
      public void keyReleased(KeyEvent e) {
  
      }
  
      @Override
      public void keyTyped(KeyEvent e) {
  
  
      }
  
  }
  </code></pre>
  
  <p>}</p>