I am going crazy trying to figure out why the paintComponent method within the locateMap class is never called. Any idea why?

`I am just trying to get the paintComponent method from the LocateMap class to run. currently it never runs.

I am trying to draw a set number of images within a jpanel based on the dimensions given from the user (the dimensions are always symmetrical). I initially tried accomplishing this from within the window class but the paintComponent method never runs even when I run it manually. I am now trying to do this from a separate LocateMap class which I still cannot get the paintComponent method to run even when I manually run repaint();. I instead tried to create a class completely separated from the Window class to see if I could get it running to a much more specific and smaller scale. The test class runs the paintComponent method automatically without me even using repaint(); I have no idea why it isn’t working but the test showed me something is stopping the paintComponent method from running.

public class LocateMap extends JPanel {

public JPanel box = new JPanel();
int dimensions;
int tileNum[][];
int individualMapDimension;
ArrayList<String> tileNums;
ArrayList<String> collisionStatus;

Tile[] tile;

String filePath = "C:\Users\Bmcar\Desktop\Coding\TossedSouls\Maps\25x25_zeros.txt";

public LocateMap(int dimensions, int tileNum[][], int individualMapDimension, ArrayList<String> tileNums,
        ArrayList<String> collisionStatus, Tile[] tile) {

    this.dimensions = dimensions;
    this.tileNum = tileNum;
    this.individualMapDimension = individualMapDimension;
    this.tileNums = tileNums;
    this.collisionStatus = collisionStatus;
    this.tile = tile;
    
    drawMap();

    this.addMouseListener(new MouseAdapter() {

        public void mouseClicked(MouseEvent e) {
            handleClick(e);
        }
    });
}

public void drawMap() {
    
    box.setLayout(new GridLayout());
    box.setLocation(1200, 150);
    box.setSize(600, 600);
    box.setBackground(Color.white);
    
    getAssetImage();
    loadMap();

}

public void getAssetImage() {

    for (int i = 0; i < tileNums.size(); i++) {
        String tempFilePath;
        boolean collision;

        tempFilePath = tileNums.get(i);

        if (collisionStatus.get(i).equals(true)) {
            collision = true;
        } else {
            collision = false;
        }
        setup(i, tempFilePath, collision);
    }
}

public void setup(int index, String imageName, boolean collision) {

    UtilityTool uTool = new UtilityTool();

    try {
        
        tile[index] = new Tile();

        BufferedImage img = ImageIO.read(new File(imageName));

        if (img == null) {
            throw new IOException("Image could not be read: " + imageName);
        }

tile[index].image = uTool.scaleImage(img, individualMapDimension, individualMapDimension);
        tile[index].collision = collision;

    } catch (IOException e) {

        e.printStackTrace();

    }
}

public void loadMap() {

    try {
        InputStream is = new FileInputStream(new File(filePath));
        BufferedReader br = new BufferedReader(new InputStreamReader(is));

        int col = 0;
        int row = 0;

        while (col < dimensions && row < dimensions) {

            String line = br.readLine();

            while (col < dimensions) {
                String numbers[] = line.split(" ");
                int num = Integer.parseInt(numbers[col]);
                tileNum[col][row] = num;
                col++;

                if (col == dimensions) {
                    col = 0;
                    row++;

                    if (row == dimensions) {
                        break;
                    }
                }
            }
        }
        br.close();

    } catch (IOException e) {
        e.printStackTrace();
    }
}

@Override
protected void paintComponent(Graphics g) {
    System.out.println("g initialized");
    super.paintComponent(g);
    System.out.println("g initialized");
    draw(g);
}

public void draw(Graphics g) {

    int mapCol = 0;
    int mapRow = 0;

    while (mapCol < dimensions && mapCol < dimensions) {

        int currentTileNum = tileNum[mapCol][mapRow];
        int mapX = mapCol * individualMapDimension + 1;
        int mapY = mapRow * individualMapDimension + 1;
        int maxMapX = 1800;
        int maxMapY = 750;
        
    if (mapX + individualMapDimension > 0 && 
    mapX < maxMapX && mapY + 

          individualMapDimension > 0
                && mapY < maxMapY) {
            
            g.drawImage(tile[currentTileNum].image, mapX, mapY, null);
            System.out.println("drawing");
        }

        mapCol++;

        if (mapCol == dimensions) {
            mapCol = 0;

            mapRow++;
            if (mapRow == dimensions) {
                break;
            }
        }
    }
}

private void handleClick(MouseEvent e) {

}

}

`

New contributor

Bmcar 4scopes is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật