Java background image on object. Can't find my public variable

What i want is that everytime a cell is considered "Dead", this image

shows on the background of the object.

I have a class called "Game" in the package p_game with the following code

public class Game{
    public Image bg_image;
    public Game(){
           //Here is code that creates a 17*17 table of cells with the status 'Dead' 
        this.Cellules= new p_cell.Cellule[17][17];  
        for (int i=1; i<17; i++){
           for (int j=1; j<17; j++){
               Cellules[i][j]=new p_cell.Cellule(i,j,"Dead");
           //Here is code for the URL and Image
           URL url;
           try {
               url = new URL("");
               bg_image = Toolkit.getDefaultToolkit().getDefaultToolkit().createImage(url);
           } catch (MalformedURLException e) {

I am trying to use bg_image in my class Cell (in the package p_cell) but it says the variable doesn't exist. What am i missing here?

public class Cell{
    public void paintComponent(Graphics g){

        g.drawImage(bg_image, 0, 0);


Error given: bg_image cannot be resolved to a variable


Every variable belongs to a class or class instance. To use bg_image you must instantiate Game class like this: Game game = new Game();, and then use it with instance reference: game.bg_image. If you don't want to have instance of Game class, you should make bg_image static and use it like this: Game.bg_image. Additional reading: about static variables: about instance variables:

Need Your Help

Calculate date from user input

javascript jquery datetime

I'm trying to create a sort of Date Calculator widget, where dates can be generated based on user inputs to different fields. Thought being if you didn't know the exact date bbut knew it was so many

NSMutable array containsObject, does it check the contents of the object or the object type?

ios nsmutablearray

I am a little confused to how containsObject works. Does it check to see if it contains an instance of an object type or does it compare the inside of the objects variables etc to see if they match?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.