paint() and repaint() in Java

I’ve spent maybe the last two hours browsing and reading up on these methods and the Graphics class, and maybe I’m stupid, haha, but I’m just not understanding them. What are they for? I understand that they’re supposed redraw or update components on the screen, but I have never understood why this is required (I’m new to this). For example, if I’m moving a JLabel around the screen, a call to setLocation() moves it just fine. Is that a scenario in which repaint() isn’t required? In which scenarios is it useful, and why?

Apologies if you feel that this is a question that could be solved using the search function, but for whatever reason I’m not getting it.

Leave a Comment