0

I didn't call super.paintMethod() in my paintMethod, yet, every time the code runs, it wipe the window clean for some reason. Any suggestions? Here's my code.

 for (int i = 0; i < 1000; i++) {

        frame.repaint();

        Thread.sleep(250);
        P.x += 50;
        if (P.x == 450) {
            P.x = 0;
            P.y += 50;
        } 
mKorbel
  • 109,525
  • 20
  • 134
  • 319
Ski
  • 111
  • 2
  • 3
  • 17
  • 2
    Show us the `paintComponent()` method you overrided. – Mordechai Mar 16 '15 at 17:17
  • What does it mean to override the paintComponent method? – Ski Mar 16 '15 at 17:20
  • 1
    This is the expected behaviour of painting, painting is destructive. On each paint cycle, the components are expected to completely repaint themselves. See [Painting and AWT and Swing](http://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java) and [Performing custom painting](http://docs.oracle.com/javase/tutorial/uiswing/painting/) – MadProgrammer Mar 16 '15 at 20:05

1 Answers1

0
    frame.repaint();

Does it. By default Component#paintComponent() will render the background color on every repaint call. Though if you override this method, and you don't call super.paintComponent(), this step is omitted, causing an overlap painting.

Mordechai
  • 15,437
  • 2
  • 41
  • 82