 <p>In general, the paint event happen after resize events. So if you resize using either the mouse or even programmatically, then the <code>drawMaze()</code> function will be called. I think you should not create the maze in <code>drawMaze()</code>, or at least make a lazy initialization. That's because a maze will be created each time the window is painted, which occurs every time you resize the window, you move the window, you hide some part of the window, you change focus, etc... That's a lot of mazes :D.</p> <p>EDIT: The paint event suggest you that the display has changed, and that the change is likely to affect the portion of the screen you are painting on. So few things:</p> <ul> <li>During a paint event you want to do only one thing: painting. So don't call garbage collection. In general calling the Gc is not a good idea, and moreover in a Listener it will just crush the performance.</li> <li>The event will not change the state of your Maze. So you should represent your maze using a state. One part is fixed, like the walls, the other side is variable, like the agent position inside the maze. Each time you modify the state, you ask a repaint.</li> <li>If you skip a paint event, the screen will be blank. </li> </ul> <p>For example if your maze is too big to fit on the screen, you use the paint event to paint only one part, etc..</p>