I am creating a small JPanel program to generate mazes. All of my code works but I want to display the maze generation in action. I edited my program to cause the paintComponent function to show the in progress maze. But I am in another class which is being passed my JPanel object so it can "refresh" the display.
What should I do that will call the paintComponent function to draw all the cells AND refresh the displays?
This is the configuration of the panel:
JPanel mainPanel = new JPanel();
mainPanel.setLayout(new BorderLayout());
gamePanel = new GamePanel();
controlPanel = new ControlPanel();
mainPanel.add(gamePanel, BorderLayout.CENTER);
mainPanel.add(controlPanel, BorderLayout.SOUTH);
mainPanel.revalidate();
This is the code expected to be called on repaint:
protected void paintComponent(Graphics pen){
if(started){
int count=0;
for (MapCell c:coms){
if (c.type!='w'){
count++;
}
c.paint(pen);
}
System.out.println("White space: " +count);
System.out.println("Components: "+coms.size());
for(Anno an:mapGen.ans){
an.draw(pen,img,colWidth,rowHeight);
}
}
The print statements work fine after the maze generation but only the image "Anno" is drawn and it leaves a trail behind it. I have confirmed the list is getting correct data.