title: Java | previous frame doesn't disappear
body: <p>I'm writing a small game in java but I have a little problem. All the rendered frames stay on the screen, so if I move the image, it just keeps rendering more images, but I want my image to move over the screen. What am I doing wrong?</p>
  
  <pre><code>public void tick(){
      balk.tick();
  }
  
  public void render(){
      BufferStrategy bs = this.getBufferStrategy();
  
      if(bs==null){
          createBufferStrategy(2);
          return;
      }
  
      Font myFont = new Font ("Courier New", 1, 50);
  
  
      Graphics g = bs.getDrawGraphics();
      ///////////////////////////////
  
      g.drawImage(balk.getBalk(), balk.getX(), 900, this);
      g.setFont(myFont); 
      g.drawString("Score: " + 0, 50, 100);
  
  
      ///////////////////////////////
      //g.dispose();
      bs.show();      
  
  }
  
  public void init(){
  
      frame = new JFrame();
  
      WIDTH = (int)Toolkit.getDefaultToolkit().getScreenSize().getWidth();
      HEIGHT = (int)Toolkit.getDefaultToolkit().getScreenSize().getHeight();
  }
  
  public static void main(String[] args){
      Game game = new Game();
      game.init();
      game.setPreferredSize(new Dimension(WIDTH, HEIGHT));
      game.setMaximumSize(new Dimension(WIDTH, HEIGHT));
      game.setMinimumSize(new Dimension(WIDTH, HEIGHT));
  
      frame.add(game);
      frame.setUndecorated(true);
      frame.setTitle("Ping Pong");
      frame.pack();
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setResizable(false);
      frame.setLocationRelativeTo(null);
      frame.setLayout(null);
  
      frame.addKeyListener(new KeyListener(){
  
  
          public void keyPressed(KeyEvent e) {
  
              int key = e.getKeyCode();
  
              if(key == KeyEvent.VK_A){
                  balk.setVelX(-5);
              }
  
              if(key == KeyEvent.VK_D){
                  balk.setVelX(5);
              }
  
          }
  
  
          public void keyReleased(KeyEvent e) {
  
              balk.setVelX(0);
          }
  
          public void keyTyped(KeyEvent arg0) {}
  
      });
  
      frame.setVisible(true);
      game.start();
  
  }   
  }
  </code></pre>