O'Reilly logo

Graphic Java™ 1.2, Volume I: AWT, Third Edition by David M. Geary

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required