I'm having a problem with loading images, than drawing them into a tile map. I read several articles about loading images but cant seem to get it right. Right now it just flashes the whole area that the map should be at green (probably the grass) then goes blank. I get no errors or anything so I'm not sure what is going on. I used this same way to draw a map but in the if files with the drawimage it was g.setColor and after the if statements g.drawRect and that worked so this looks like it should adapt fine.
Code:import java.applet.*;
import java.awt.*;
public class helloworld extends Applet
{
int[][] map = { //simple map each square is 16 x 16 pixels might change it to 32
{1,1,1,1,1,1,1,1,1,1,1,1,1,0,1}, //the height and width is 240
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
};
int x = 0; // x,y for the array
int y = 0;
int xmap = 0; // x,y for drawing the array
int ymap = 0;
public void paint (Graphics g)
{
//Image grass = getImage(getCodeBase(),"grass.gif"); //also tried it this way
//Image water = getImage(getCodeBase(),"water.gif");
Image grass = Toolkit.getDefaultToolkit().getImage(getClass().getResource("grass.gif"));
Image water = Toolkit.getDefaultToolkit().getImage(getClass().getResource("water.gif"));
g.drawString("Ran",10,290); //just says if it ran or not
while (y<=14) //draws out the map
{
if (map[y][x] == 0) // grass
{
g.drawImage(grass, xmap, ymap, this);
}
if (map[y][x] == 1) // wall
{
g.drawImage(water, xmap, ymap, this);
}
if (map[y][x] == 2) // start
{
g.drawImage(grass, xmap, ymap, this);
}
if (map[y][x] == 3) // end
{
g.drawImage(grass, xmap, ymap, this);
}
x++;
xmap = xmap + 32;
if (x >= 15)
{
x = 0;
xmap = 0;
y++;
ymap = ymap + 32;
}
}
}
}

