title: How can i return a value from a void method in java
body: <p>Ok so i have this code and obviously the "g = gd" from the render method isnt modifying the field value of "g".</p>
  
  <p>How can i make it so that the render method modifies the field g?</p>
  
  <p>I want to have a graphics field so i can use graphics to print strings outside the render method but i really have no idea how to do that.</p>
  
  <pre><code>private Graphics g;
  
  private BufferedImage background;
  
  public Tutorial(Core core){
      background = core.getResources().getImage(4);
  }
  
  public void render(Graphics gd) {
      g = gd;
      g.drawImage(background, 0, 0, null);
  }
  </code></pre>
  
  <p>EDIT:</p>
  
  <p>ok this is the whole class how can i modify it so that the displayMessage will work ?
  tick() is called before render() , that might be a problem?</p>
  
  <pre><code>package com.andrewxd.spaceinvaders.levels;
  
  import java.awt.Color;
  import java.awt.Font;
  import java.awt.Graphics;
  import java.awt.image.BufferedImage;
  
  import com.andrewxd.spaceinvaders.main.Core;
  
  public class Tutorial implements Levels{
  
      private Graphics g;
  
      private BufferedImage background;
  
      public Tutorial(Core core){
          background = core.getResources().getImage(4);
      }
  
      public void render(Graphics gd) {
          g = gd;
          g.drawImage(background, 0, 0, null);
      }
  
      public void tick() {
          displayMessage("Welcome", 200,200);
      }
  
      public void displayMessage(String message, int x, int y) {
          g.setFont(new Font("ARIAL", Font.BOLD, 20));
          g.setColor(Color.RED);
          g.drawString(message, x, y);
      }
  
      public void displayMessage(String message, int x, int y, Font font) {
          g.setFont(font);
          g.setColor(Color.WHITE);
          g.drawString(message, x, y);
      }
  
      public void displayMessage(String message, int x, int y, Font font, Color color) {
          g.setFont(font);
          g.setColor(color);
          g.drawString(message, x, y);
      }
  
  }
  </code></pre>