Creating a Graphics
When implementing a method that is passed a Graphics reference, it is best to ensure that the method results in no net change to the Graphics. In other words, when the method returns, the Graphics should be in the same state that it was in before the method was invoked.
There are exceptions to this rule, of course. For instance, we can have a high degree of certainty that callers of paint(Graphics) will merely dispose of the Graphics when the call to paint() returns. Therefore, it is acceptable to modify the Graphics passed to paint() with wanton disregard to maintaining its state.
However, in other situations it is not so clear as to whether the Graphics must retain its initial state. In such cases, it is best to take the ...