repaint() method inside ActionListener and paintComponent method

38 views Asked by At

So i've created a Snake game but i have somekind fo a theoretical question.

Im using paintComponent to drawImage every pixel, but im also implementing ActionListener so im bound to using actionPerformed method.

my question is: why using repaint() method inside actionPerformed, what is the logic behind that?

public void actionPerformed(ActionEvent e) {
    checkCollusion();
    move2();
    repaint();
}

i tried removing repaint() method but seems like it stopped updating. myquestion is it necessary for using paintComponent again?

0

There are 0 answers