This question is a bit long, I'll leave a tl;dr at the bottom.

I'm trying to make a simple game, the map system is simply a 2-dimensional array, where the value of each point in the array represents an image that can be rendered. The game is supposed to render the 11x11 square in the map that surrounds the player. The problem is, I can't figure out how to draw images with the application from a static context. I have the following code:

Code:
package dungeonRaider;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.ImageObserver;

public class Main extends Frame{
	
	public static Graphics d;
	public static Image[] cave = new Image[20];
	public static MediaTracker mt;
	public static int[][] currentMap;
	public static ImageObserver io;
	
	public Main(){
		super("Dungeon Raider");
	    mt = new MediaTracker(this);
	    setSize(368,390);
	    setVisible(true);
	    addWindowListener(new WindowAdapter(){
	      public void windowClosing(WindowEvent we){
	        dispose();
	      }
	    });
	}
	
	public static void importImages(){
		Toolkit tk = Toolkit.getDefaultToolkit();
		
		cave[0] = tk.getImage("cave/outside.jpg");
		mt.addImage(cave[0],0);
		
		cave[1] = tk.getImage("cave/floor.jpg");
		mt.addImage(cave[1],0);
		
		cave[2] = tk.getImage("cave/north.jpg");
		mt.addImage(cave[2],0);
		
		cave[3] = tk.getImage("cave/south.jpg");
		mt.addImage(cave[3],0);
		
		cave[4] = tk.getImage("cave/west.jpg");
		mt.addImage(cave[4],0);
		
		cave[5] = tk.getImage("cave/east.jpg");
		mt.addImage(cave[5],0);
		
		cave[6] = tk.getImage("cave/inne.jpg");
		mt.addImage(cave[6],0);
		
		cave[7] = tk.getImage("cave/inse.jpg");
		mt.addImage(cave[7],0);
		
		cave[8] = tk.getImage("cave/insw.jpg");
		mt.addImage(cave[8],0);
		
		cave[9] = tk.getImage("cave/innw.jpg");
		mt.addImage(cave[9],0);
		
		cave[10] = tk.getImage("cave/outne.jpg");
		mt.addImage(cave[10],0);
		
		cave[11] = tk.getImage("cave/outse.jpg");
		mt.addImage(cave[11],0);
		
		cave[12] = tk.getImage("cave/outsw.jpg");
		mt.addImage(cave[12],0);
		
		cave[13] = tk.getImage("cave/outnw.jpg");
		mt.addImage(cave[13],0);
		
		cave[14] = tk.getImage("cave/.jpg");
		mt.addImage(cave[14],0);
		
		cave[15] = tk.getImage("cave/.jpg");
		mt.addImage(cave[15],0);
		
		cave[16] = tk.getImage("cave/exit.jpg");
		mt.addImage(cave[16],0);
	}
	
	public static void main(String[] args) {
		int[][] ar = new int[1][1];
		int size = 10;
		int nrooms = 15;
		ar[0][0] = -999;
		Map map = new Map(ar,8,nrooms,3,size);
		currentMap = map.getMapData();
        /*for(int y = 35+size*20; y >= 1; y--){
        	for(int x = 1; x <= 50; x++){
        		System.out.print(newMap[x][y]);
        	}System.out.println();
        }*/
		
		Main out = new Main();
		
		Player.x = 26;
		Player.y = 2;
	    importImages();
		//drawDungeon();
    }
	
	public static void drawDungeon(){
		for(int x = 0-5; x <= 5; x++){
			for(int y = 0-5; y <= 5; y++){
				try{
					img(
						cave[currentMap[Player.x+x][Player.y+y]],
						x*32+1,
						y*32+1
					);
				}catch(Exception e){
					img(
						cave[0],
						x*32+1,
						y*32+1
					);
				}
			}
		}
	}
	
	public void update(Graphics g){
		io = this;
	    paint(g);
	}
	
	public void paint(Graphics g){
		g.drawImage(cave[0],32,32,this);
		d = g;
	}
	
	public static void square(int x, int y, int width, int height){
		d.fillRect(x+8, y+30, width, height);
	}
	
	public static void img(Image img, int x, int y){
		d.drawImage(img, x+8, y+30, 32, 32, io);
	}

}
I don't know entirely how the method, update(Graphics g) works, I got it from a site, I just know it seems to be called when the Frame is opened. I realized that if I made the Graphics object static, I should be able to access it from any method within the Main class, which is what I wanted to do, so I made a static Graphics variable, d, equal to the default variable, g. This worked. The problem I'm having is with the image observer. I can't use the keyword, this, from a static context, so I tried doing the same thing I did with the Graphics. I made a static ImageObserver, io, equal to this, but when I try to draw an image with it, it doesn't work, even within the paint method. When I try to access it within a static method (img, for example), it gives me a NullPointerException for the drawImage method. Does anyone know how I can draw to the frame from a static context?



tl;dr: How do you output to a Frame from a static context in a java application (using AWT graphics)?