I have method that writes how many guesses there are left and I want it to be repainted every time person misses letter or word, however it keeps repainting itself all the time and that causes whole program constantly flash.
My method looks like this:
public void repaintWord(Graphics g){
g.SetColor(Color.RED);
g.drawString("You have " + getN() + " guesses left", 400, 50);
repaint();
}
How to make it repaint only once when getN() changes its value?
Store the value of
getN()whenrepaintWord()last exited and compare withgetN()onentrance: