In the above code I am trying to understand how inner classes work. I know that they have access to outer objects instance variables but if you have two inner classes do they have access to each others variables? This is whats happening in this code. A ball goes from top right to bottom left of screen. I am trying to have a button that when clicked it starts the process again. The code works until you click the button to repaint it. This buttons action listener is a inner class. What happens when I click the button is nothing. The method doIncrement() is run but the drawPanel.repaint(); does not execute. It doesnt go to the other inner classes paintComponent method? Any ideas would be great!! [ August 11, 2004: Message edited by: jim gemlo ]
I think the problem is that, when you call doIncrement() from the ActionListener, you're running it in the event dispatch thread (all action handlers run in the event dispatch thread). Any thread that runs doIncrement() spends most of its time asleep and therefore has no time to do anything else (e.g. repaint the panel).
You need to look at using a Timer to control your animation instead. You may also want to look at SwingUtilities.invokeLater() which is used to add events to the event queue.