O'Reilly logo

Ivor Horton's Beginning Java™ 2, JDK™ 5th Edition by Ivor Horton

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

20.4. Transforming the User Coordinate System

I said when you started learning how to draw on a component that the drawing operations are specified in a user coordinate system, and the user coordinates are converted to a device coordinate system. The conversion of coordinates from the user system to the device system is taken care of by the methods in the graphics context object that you use to do the drawing, and they do this by applying a transformation to the user coordinates. The term transformation refers to the computational operations that perform the conversion.

By default, the origin, the (0, 0) point in the user coordinate system, corresponds to the (0, 0) point in the device coordinate system. The axes are also coincident, too, with positive x heading from left to right, and positive y from top to bottom. However, you can move the origin of the user coordinate system relative to its default position. Such a move is called a translation, and this is illustrated in Figure 20-15.

A fixed value, deltaX, say, is added to each x coordinate, and another value, deltaY, say, is added to every y coordinate, and the effect of this is to move the origin of the user coordinate system relative to the device coordinate system: Everything will be shifted to the right and down compared to where it would have been without the translation. Of course, the deltaX and deltaY values can be negative, in which case it would shift things to the left and up.

Figure 20.15. Figure 20-15

A translation ...

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