Results 1 to 4 of 4
  1. #1
    DaveAp7 is offline Member
    Join Date
    Feb 2012
    Posts
    5
    Rep Power
    0

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

    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

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default 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

  3. #3
    DaveAp7 is offline Member
    Join Date
    Feb 2012
    Posts
    5
    Rep Power
    0

    Default 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.

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default 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.

Similar Threads

  1. How to make a morph Method
    By AnthonyTTaylor in forum Java 2D
    Replies: 6
    Last Post: 11-15-2011, 11:41 PM
  2. I want to make an array in a method...
    By nhmllr in forum New To Java
    Replies: 7
    Last Post: 10-02-2011, 08:18 AM
  3. Java installation continually repeats
    By BobW56 in forum Forum Lobby
    Replies: 1
    Last Post: 01-01-2011, 11:21 PM
  4. creating a make grid method
    By Matt198525 in forum New To Java
    Replies: 13
    Last Post: 10-29-2010, 02:47 AM
  5. Static method cannot make new objects?
    By zerkz in forum New To Java
    Replies: 2
    Last Post: 10-15-2009, 03:17 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •