Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

why is my entire Java program flashing?

http://pastebin.com/b6i2CEBm

Whenever I run my program it flashes- from a grey color to the game. The controls work fine- for a little bit, then they just stop working. I don't think there is an error in my Move1 or Move2 classes, because it happens even if I don't press a button. Help?

2 Answers

Relevance
  • McFate
    Lv 7
    9 years ago
    Favorite Answer

    Just a suggestion: where you call "repaint()", try calling "invalidate()" and then "repaint()".

    Swing components keep a buffer (copy) of their display image and unless told that it is invalid, can refresh from that. invalidate() tells the window to be sure it redraws from scratch.

    @M

  • 9 years ago

    In your paint function, comment out this line:

    super.paint(g);

    The super class is repainting the ENTIRE window by filling it with gray. Then you have to redraw everything from scratch. That will flicker for sure.

    You don't need to call super.paint here because you are doing all the paint operations. Or, at least you want to be. You'll have a bit of work to do to make it work (you'll notice that your draw code is working, but now your old stuff isn't being erased (because the erase is the one thing super was doing for you). You'l have to figure out how to erase your tracks.

Still have questions? Get your answers by asking now.