I'm getting late, but I'll give him a quick shot. An instance of Graphics (or Graphics2D) is an abstraction of a graphics device (such as a printer, screen, etc.). It has borders. Suppose you want to use only a specific area of ββthe device and want the code to always be relative to (0,0) (for example, a game in which a sprite moves around the screen). The sprite will always be the same, but its location will be different. One way to achieve this is to create a Graphics2D that limits output to a subset of the main Graphics2D. Something that
public Graphics create(int x,int y,int width,int height)
will do for you. I think the other Graphics2D attributes are also independent. This means that the Paint setting in the second Graphics2D will not affect the main one.
public abstract void translate(int x,int y)
- all about moving the orgine (but not in the direction of the axis). By default, the source will be the upper left corner of the device. This can be changed anywhere on the device. Using the above example of a sprite moving around the screen, just call up the translation where you want to draw it, and then draw it.
source share