File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Help me understand Inner Classes with code example provided Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Help me understand Inner Classes with code example provided" Watch "Help me understand Inner Classes with code example provided" New topic
Author

Help me understand Inner Classes with code example provided

jim gemlo
Greenhorn

Joined: Feb 24, 2004
Posts: 20


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 ]
Julian Kennedy
Ranch Hand

Joined: Aug 02, 2004
Posts: 823
Hi Jim,

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.

Hope this helps.

Jules
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help me understand Inner Classes with code example provided
 
Similar Threads
help me it is a simple code but i need help
Event Problems: Need Help
learning GUI
this animation code does not show o/p
script question