Ok i dont know how much experience you have with programming, so ill just explain it basically. If anything is unclear to you, please say so!
Im using the following class to get data from an text file, and return it as a 2d array:
import java.io.FileReader;
import java.io.IOException;
import java.io.LineNumberReader;
import java.util.ArrayList;
public class MapToArray {
private final String filename;
//Simple constcructor. Taking the name of your map as argument ( in String) for example: MapToArray("level1.txt")
MapToArray(String filename) {
this.filename = filename;
}
//This function will return the 2d array of the map, in INT[][]
public int[][] getArray() throws IOException {
ArrayList<String> array = new ArrayList<String>();
int length = getLength();
int height = getHeigth();
LineNumberReader reader = new LineNumberReader(new FileReader(filename));
for (int i = 0; i < height; i++) {
array.add(reader.readLine());
}
if (array.size() == 0) {
System.out.println("Empty map");
}
int[][] numbers = new int[length][height];
int r = 0;
//Now that we have decided the size of our 2d array, we will fill it in
for (String s : array) {
toArray(s, r, numbers);
r++;
}
return numbers;
}
//Since an array is static, we must find its boundaries. This function will return the amount of characters in the map.
private int getLength() throws IOException {
int countChar = 0;
try {
LineNumberReader reader = new LineNumberReader(new FileReader(filename));
String lineRead = reader.readLine();
int length = 0;
while (countChar < lineRead.length()) {
if (!(lineRead.charAt(countChar) == ',')) {
length++;
}
countChar++;
}
reader.close();
return length;
} catch (IOException e) {
throw e;
}
}
//This will return the height of the map (the amount of lines)
private int getHeigth() throws IOException {
try {
LineNumberReader reader = new LineNumberReader(new FileReader(filename));
@SuppressWarnings("unused")
String lineRead;
while ((lineRead = reader.readLine()) != null) {
}
int height = reader.getLineNumber();
reader.close();
return height;
} catch (IOException e) {
throw e;
}
}
//This function will fill an entire row with the numbers from String s.
private void toArray(String s, int row, int[][] numbers) {
String match = ",";
String[] veld = s.split(match);
for(int i = 0; i<veld.length;i++)
veld[i] = veld[i].replaceAll(" ","");
for (int i = 0; i < veld.length; i++) {
try {
numbers[i][row] = Integer.parseInt(veld[i]);
} catch (NumberFormatException e) {
System.out.println("Not a valid map!");
}
}
}
}
Ok so now we have a class which will take the map location as input, and returns the 2d array as output. Note this is NOT necessary, but it makes everything a lot easier to manage, reuse and saves up precious source code space.
so this is how we can use it:
int[][] array_map1;
MapToArray map1 = new mapToArray("level 1.dat");
array_map1 = map1.getArray();
where level1.dat contains the following:
1,1,1,1,1,
1,0,0,0,1,
1,0,2,0,1,
1,0,0,0,1,
1,1,1,1,1,
Where 1 are the walls, 2 is a table for example. Now you have the array, whats next?
You want to draw everything on the screen. For this im not quite sure what you exactly need at this point. A class which loads the images of a tilesheet? ill just give you a simplefied version of my code:
package nl.elmar.grafics;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
import nl.elmar.items.Coin;
import nl.elmar.items.Key;
import nl.elmar.items.Sword;
import nl.elmar.other.Common;
public class ArrayToGraf {
Image image;
//ignore this part
Sprite sprite = new Sprite("terrainSheet.png", 1, 15, false);
int x,y,temp=0;
//nothing here yet
public ArrayToGraf(){
}
//This function will return an BufferedImage with all the tiles drawn on it
public BufferedImage getMap(int[][] map){
BufferedImage bufferedImage = new BufferedImage(map.length*4, (map[0].length)*15, BufferedImage.TYPE_INT_BGR);
Graphics2D g2d = bufferedImage.createGraphics();
g2d.setColor(Color.green);
g2d.fillRect(0, 0, map.length*4, (map[0].length)*15);
for(int heigth = 0; heigth<map[0].length; heigth++){
for(int length = 0; length<map.length; length++){
x=0;
temp = map[length][heigth];
while(temp>=10){
x++;
temp-=10;
}
y=temp;
g2d.drawImage(sprite.getImage(x, y), length*15, heigth*15, null);
}
}
g2d.finalize();
g2d.dispose();
return bufferedImage;
}
}
Now my code is probably using methods which you dont have. Im using a sprite sheet, which is much easier for me.
How you can do it, with the map i gave as example, is:
//Add the following 2 lines as variables in your class
private Image wall = Toolkit.getDefaultToolkit().getImage("Map/Wall.png");
private Image table = Toolkit.getDefaultToolkit().getImage("Map/Table.png");
private Image floor = Toolkit.getDefaultToolkit().getImage("Map/Floor.png");
Now the computer knows what a wall looks like, and what a table looks like. But he doesnt know where to place them. So we change the for loop given in my previous class.
change this:
for(int length = 0; length<map.length; length++){
x=0;
temp = map[length][heigth];
while(temp>=10){
x++;
temp-=10;
}
y=temp;
g2d.drawImage(sprite.getImage(x, y), length*15, heigth*15, null);
}
to this:
for(int length = 0; length<map.length; length++)
switch(map[length][heigth]){
case 0:
g2d.drawImage(floor, length*15, heigth*15, null);
break;
case 1:
g2d.drawImage(wall, length*15, heigth*15, null);
break;
case 2:
g2d.drawImage(table, length*15, heigth*15, null);
break;
}
}
Why *15? you would ask. Well this is the size of each tile of yours. Im using 15 myself, but change to your liking!
So how to totally implement it?
This is how i have done it:
..... your main drawing class here...
int[][] array_map1;
MapToArray map1;
Image bckground_1;
ArrayToGraf draw = new ArrayToGraf();
Constructor(){
map1 = new mapToArray("level 1.dat");
array_map1 = map1.getArray();
bckground_1 = draw.getMap(array_map1.getArray());
}
Yes this could be smaller:
background = draw.getMap(map1.getArray(), objects1.getArray());
Now all you have to do is draw your image, its as simple as that! 
Any problems ? ask me!
dont forget to give me a medal for my hard work of explaining! 