Doubt regarding the dispose () and repaint () methods

2

What is the function of .dispose() and repaint() methods in using Graphics in Java?

    
asked by anonymous 12.03.2018 / 03:34

1 answer

2

If you are referring to the method dispose() class Graphics , as stated in the documentation itself, it serves to release the system resources that this class uses when you create an instance of it.

Consider that, since this class has a basic importance in creating everything you see on the screen, it can consume many system resources, as well as have multiple instances associated with it. Still according to the documentation, the JVM garbage collector can usually deal with this, but giving dispose() , you can ensure with a little more efficiency that these resources used will in fact be released. Remember that an instance of Graphics can no longer be used after this method is called.

The repaint() method, as already explained in this other answer , is intended to warn you that the screen needs to be redrawn, possibly because some area has undergone some alteration, and so the screen is all redesigned and is displayed with the updates made on it.

    
12.03.2018 / 03:53