• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help me understand Inner Classes with code example provided

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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 ]
 
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 am displeased. You are no longer allowed to read this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic