title: How to bring an image to the foreground in Java?
body: <p>I'm trying to create a Pacman game in Java, and so far I've displayed the background image (the blue and black maze), but I'm having trouble showing the image of Pacman. When I try to display him in the same method with which I displayed the background, he doesn't appear unless I slightly manually alter the size of the Jframe. And even then when he appears there's a small white square in the bottom right corner of his image. What can I do to fix this? Is there any other way I can insert the pacman image in that works?</p>
  
  <p>This is the code:</p>
  
  <pre><code>  JFrame window = new JFrame();
  
    ImageImplement pacman = new ImageImplement(new ImageIcon("C:\\Users\\16ayoubc\\Desktop\\Pacman-moving.gif").getImage());  
    ImageImplement panel = new ImageImplement(new ImageIcon("C:\\Users\\16ayoubc\\Desktop\\background.png").getImage());
  
    pacman.setLocation(255, 255);
    pacman.setVisible(true);
    pacman.setOpaque(true);
    window.add(pacman);
    window.add(panel);
  
    window.setVisible(true);
    window.setSize(576,655);
    window.setName("Pacman");
    window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  </code></pre>