title: How to initialize Graphics g?
body: <p>I want to display a GameOver image in a pacman game after lives are over. But I call the paintGameOverScreen(Graphics g) and then I need to initialize g. Is there any other way to do this?</p>
  
  <p>This is my Lives class</p>
  
  <pre><code>import java.awt.Color;
  import java.awt.Graphics;
  import java.awt.Image;
  import java.awt.image.BufferedImage;
  
  import javax.imageio.ImageIO;
  import javax.swing.ImageIcon;
  
  
  public class Lives{
  
  private int lives;
  
  
  public Lives() {
      lives = 1;
  }
  
  public void removeLife() {
  
          lives--;
          if(lives==0){
              System.out.println("END GAME");
              paintGameOverScreen(g);
              System.exit(0);
          }
  }
  
  public void paintGameOverScreen(Graphics g) {
  
  
              ImageIcon i = new ImageIcon("src\image");
              Image image = i.getImage();
              int x = 0;
              int y = 0;
              g.drawImage(image, x, y, 100,100,null);
  }
  
  
  public void paint(Graphics g) {
      g.setColor(Color.WHITE);
      g.fillRect(5*20, 25*20, 100, 30);
      g.setColor(Color.BLACK);
      String result = "Lives: " + lives;
      g.drawString(result, 6*20, 26*20);
  }
  }
  </code></pre>