title: BufferedImage not being cleared before each rendering
body: <p>I'm trying to learn how to build a simple game through a tutorial i'm watching. Up to now everything was fine, but when I move the image the previous image doesn't get erased or disposed. I'm not sure exactly whats wrong, or why its happening. I have 3 classes, a main class, player class, and a bufferimageloader class.</p>
  
  <p>Main class:</p>
  
  <pre><code>import java.awt.Canvas;
  import java.awt.Graphics;
  import java.awt.image.BufferStrategy;
  import java.awt.image.BufferedImage;
  import java.io.IOException;
  
  import javax.swing.JFrame;
  
  public class Main extends Canvas implements Runnable {
  private boolean running = false;
  private Thread thread;
  private BufferedImage player;
  private Player p;
  
  public void init(){ // load and initiliaze
      BufferedImageLoader loader = new BufferedImageLoader();
  
      try {
          player = loader.loadImage("/player_shotgun2.png");
      } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  
      p = new Player(100, 100, this);
  
  }
  
  private synchronized void start(){
  if(running)
      return;
  running = true;
  thread = new Thread(this);
  thread.start();
  }
  
  private synchronized void stop(){
      if(!running)
          return;
      running = false;
      try {
          thread.join();
      } catch (InterruptedException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
      System.exit(1);
  }
  
  public void run() {
      init();
      long lastTime = System.nanoTime();
      final double amountOfTicks = 60.0;
      double ns = 1000000000 / amountOfTicks;// 1 second divided by 60, run 60 times per second
      double delta = 0;
      int updates = 0;
      int frames = 0;
      long timer = System.currentTimeMillis();
      System.out.println("hi");
      while(running){
          long now = System.nanoTime();
          delta += (now - lastTime) / ns;
          lastTime = now;
          if(delta &gt;= 1){// delta = 1 = 1 second
              tick();
              updates++;
              delta--;
          }
          render();
          frames++;
          if(System.currentTimeMillis() - timer &gt; 1000){
              timer+= 1000;
              System.out.println(updates + " Ticks, Fps " + frames);
              updates = 0;
              frames = 0;
          }
      }
      stop();
  }
  
  // Everything thats is updated in the game
  private void tick(){
      p.tick();
  }
  
  // Everything that is rendered in the game
  private void render(){
      BufferStrategy bs = this.getBufferStrategy();
      if(bs == null){
          createBufferStrategy(3);
          return;
      }
      Graphics g = bs.getDrawGraphics();
      //////////////////////////////
      p.render(g);
  
      //////////////////////////////
      g.dispose();
      bs.show();
  }
  
  public static void main(String[] args) {
      // TODO Auto-generated method stub
      Main main = new Main();
      JFrame window = new JFrame();
      window.setSize(500,600);
      window.setTitle("Zombie Game");
      window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      window.setVisible(true);
      window.add(main);
      main.start();
  }
  
  public BufferedImage getPlayerImage(){
      return player;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Player class:</p>
  
  <pre><code>import java.awt.Graphics;
  import java.awt.image.BufferedImage;
  
  import javax.swing.JPanel;
  
  public class Player extends JPanel {
  
      private double x;
      private double y;
      public BufferedImage player;
  
      public Player(double x, double y, Main main){
          this.x = x;
          this.y = y;
  
          player = main.getPlayerImage();
      }
  
      public void tick(){
          x++;
      }
  
      public void render(Graphics g){
          super.paintComponent(g);
          g.drawImage(player, (int)x, (int)y, null);
          g.dispose();
      }
  }
  </code></pre>
  
  <p>Bufferedimageloader class:</p>
  
  <pre><code>import java.awt.image.BufferedImage;
  import java.io.IOException;
  
  import javax.imageio.ImageIO;
  
  public class BufferedImageLoader {
  
      private BufferedImage image;
  
      public BufferedImage loadImage(String path) throws IOException{
          image = ImageIO.read(getClass().getResource(path));
          return image;
      }
  }
  </code></pre>
  
  <p>This is the output I get when I start up and the image moves:</p>
  
  <p><a href="https://i.stack.imgur.com/kVeVK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kVeVK.png" alt="enter image description here"></a></p>