• 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

Problem with graphics and sound

 
Ranch Hand
Posts: 94
1
Oracle Notepad Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

The above code makes a frame,puts a button and a circle on the frame,everything runs fine but i do not understand one thing,i hava enclosed the code for playing sound and repaint() method in a for loop that iterates five times,when i click the button the sound plays 5 times but the color of the of the circle changes only once per click although call to repaint() method is enclosed in the same loop.Can anyone please tell me why it is behaving that way.
 
Ranch Hand
Posts: 606
11
Android Python Open BSD VI Editor Slackware
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rrohit rakesh upadhyay wrote:


Ciao, this forum stimulates curiosity and reasoning, I challenge you to put repaint() like above in the overwritten class Paint and to eliminate from the for cicle...
and it does just the opposite
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do NOT call repaint() from within a painting method. Not here, not ever.
 
Rrohit rakesh upadhyay
Ranch Hand
Posts: 94
1
Oracle Notepad Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
but why not to put repaint() in paint component
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That should become obvious if you try it
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving discussion to the GUIs forum.
 
Bartender
Posts: 5465
212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What about infinite loops? And the consequences for the EDT itself (it
would get flooded with these repaint commands).

About your question: I think that all your 'repaint' commands are
coalesced into one repaint command, for efficiency reasons. That's why
you only see just one color.

If you want to see these colors, without creating an infinite loop, is
to start a timer, that fires, say, 60 times a second, and in its
actionListener repaints the Panel. When the music stops, you simply stop
the timer.

Greetz,
Piet
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are three sorts of Timer built in inJava®. You probably want the one described in the Java Tutorials.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic