My small program is supposed to read from a .txt file named map1.txt and store the chars in it in an Char[][] array. Depending on the chars in my map1.txt my Tile class draw red if char is ‘x’ or else draws green. (Instead the program shows what´s behind the panel instead of boxes in red and green. EDIT).

public class MainClass extends JPanel {
static Tile[][] tile = new Tile[SomeInts.amount][SomeInts.amount];
static Map map = new Map();
public MainClass () {
this.setBackground(Color.white);
}
public void paintComponent(Graphics g){
super.paintComponent(g);
for (int x = 0; x < SomeInts.amount; x++){
for (int y = 0; y < SomeInts.amount; y++){
tile[x][y].colorBody(g, x, y);
}
}
}
//Most important
public static void main(String[] args) {
JFrame f = new JFrame();
f.setSize(500, 500);
f.setLocation(100,100);
f.setTitle("Test");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
MainClass p = new MainClass ();
f.add(p);
f.setVisible(true);
//load map
map.loadMap();
for (int x = 0; x < SomeInts.amount; x++){
for (int y = 0; y < SomeInts.amount; y++){
tile[x][y] = new Tile();
}
}
for (int x = 0; x < SomeInts.amount; x++){
for (int y = 0; y < SomeInts.amount; y++){
tile[x][y].setType(map.charmap[x][y]);
}
}
}
}
public class Tile {
char type = 'a';
public void setType(char c){
type = c;
}
public void colorBody(Graphics g, int x, int y){
if (type == 'x'){
g.setColor(new Color(255, 0, 0));
g.fillRect(x * 10, y * 10, 10, 10);
}
else{
g.setColor(new Color(0, 255, 0));
g.fillRect(x * 10, y * 10, 10, 10);
}
}
}
public class Map {
public char[][] charmap = new char[SomeInts.amount][SomeInts.amount];
public void loadMap(){
BufferedReader in = null;
try {
in = new BufferedReader(new FileReader("map1.txt"));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
String line = null;
try {
line = in.readLine();
} catch (IOException e) {
e.printStackTrace();
}
while (line != null){
int y = 0;
for (int x = 0; x < line.length(); x++){
charmap[x][y] = line.charAt(x);
}
y++;
}
}
//Not used but does work
public void createMap() {
for (int x = 0; x < SomeInts.amount; x++){
for (int y = 0; y < SomeInts.amount; y++){
charmap[x][y] = 'x';
}
}
}
}
The code you are showing has a infinite loop, your thinking here is a bit off.
The logic you have reads a line, and then it loops as long as that line is not null. Either the line was null form the beginning or it wasn’t, it will not change by itself. You need to read a new line once you processed the current one.
You also need to move the reset of y to 0 out of the loop. Now you set y to 0, increase it by one and then set it back to 0 again.