Results 1 to 4 of 4
  1. #1
    cyentw is offline Member
    Join Date
    Jan 2013
    Posts
    14
    Rep Power
    0

    Default How to tell another class to repaint() ?

    That's all. It has to be from another class because the other class controls the fps timer, and I want it to repaint() the panel every tick. However, I cannot seem to find a way to do this because repaint() is not static, and therefor can not be called in any way from another class.



    Thanks!

  2. #2
    cyentw is offline Member
    Join Date
    Jan 2013
    Posts
    14
    Rep Power
    0

    Default Re: How to tell another class to repaint() ?

    Nevermind, I got it. I just made the class which wanted to repaint extend the class that it was painting. I'll just leave this post up, in case anyone else has a similar problem.

  3. #3
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,036
    Rep Power
    6

    Default Re: How to tell another class to repaint() ?

    You can also pass an instance of your paintable class to the timer class. This is known as delegating and I believe this might be a better approach than to simply have timer extend the paintable class (if that's what you were suggesting).

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  4. #4
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: How to tell another class to repaint() ?

    Swing repainting is asynchronous. You won't have much success getting things to repaint at fixed intervals, and you shouldn't try. Instead, just call repaint() (or one of the versions with parameters to specify a region) every time something changes. Calling repaint just marks the component or region as dirty. Swing will automatically merge dirty regions and repaint them as quickly and efficiently as it can.
    Get in the habit of using standard Java naming conventions!

Similar Threads

  1. repaint()?
    By santa in forum New To Java
    Replies: 10
    Last Post: 01-29-2012, 03:43 AM
  2. repaint every
    By 3xpr1ment in forum AWT / Swing
    Replies: 10
    Last Post: 03-23-2010, 06:39 PM
  3. repaint class doesnt work anymore... dunno why..
    By Addez in forum New To Java
    Replies: 9
    Last Post: 11-07-2009, 10:10 PM
  4. Repaint problem
    By citizenXL in forum New To Java
    Replies: 4
    Last Post: 10-28-2009, 04:02 PM
  5. Help with repaint() command
    By GeoffTK in forum New To Java
    Replies: 2
    Last Post: 11-26-2008, 05:33 AM

Posting Permissions

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