I'm new to making applications and currently use the JPanel paintcomponent() to draw all my page.fillRect's and ..Oval's. However, I want to make an application that is always in movement; that always updates itself and the objects in the JPanel as I interact with it via mouse and keyboard. How would I do that? I tried making an infinite while(true) loop in the paintcomponent() method but I learned that the Graphics don't actually display until we reach the very end of the method so the while(true) loop didn't work.

Is there something other than a JPanel paintcomponent() that will constantly update itself?
Thank you for taking the time to review my question.
David A. Perez

03-25-2012, 08:13 AM

pbrockway2

Re: How do I make a method that repeats itself at 30 fps?

Components paint themselves when they are told. (They tend to do this quickly and, as you have found, no visual change takes place until they are done.)

So what you need is something to tell the component repeatedly to repaint. This is what Swing timers are for.

[Edit] Moving to the AWT/Swing forum

03-25-2012, 09:11 AM

DaveAp7

Re: How do I make a method that repeats itself at 30 fps?

Thank you so much!
Sorry for asking this question in the wrong thread. I'm still fairly new to the forum.
D.P.

03-25-2012, 09:24 AM

pbrockway2

Re: How do I make a method that repeats itself at 30 fps?

You're welcome.

Don't worry about misplacing the question - it takes some getting used to the locations of everything. But it helps everybody to keep things organised: putting it here will raise the visibility of the question in the eyes of the resident Swing experts. Post back if you have any problems understanding what it says in the Tutorial.