I have a collections of agents (objects), when the simulator begins each agent performs a act() method which updates their location in the environment (2D Array). My paintComponent(Graphics g) is overridden in a different class (which basically iterates through the 2D array and draws a rectangle colour corresponding to the type of agent).
But the actual collection is in the simulator class which run independently by the user clicking a button from the GUI. If I put the repaint() method at the end of the paintComponent(Graphics g). It only updates the JPanel canvass twice, once when the application start-up and second when I click the run button that starts simulation.
How do I have the JPanel canvass update automatically with the new image when all the agents perform the act method. Or perhaps when a change happens in a collection to a agent draw the new location on the canvass and remove the old one ?