A large number of the methods supported by the Graphics object depend on numerical coordinates. Such coordinates can be specified in a Rectangle object, which specifies the area in which an operation is to occur, or in a Point object, which specifies the x (horizontal) and y (vertical) coordinates at which the operation occurs.
The term coordinate system identifies how the coordinates specified in such objects map to the display or to a device. Suppose, for example, that you call the Graphics object’s drawString method to draw text at coordinates 100, 100:
Graphics g = this.createGraphics();
g.drawString(“Hello, WFC”, new Point(100, 100));
The Point object in this example specifies the x and y coordinates at which to draw the string. However, the actual result of this operation depends on the coordinate system with which the Graphics object is associated.
The coordinate systems with which you can associate a Graphics object are defined in the CoordinateSystem class. The default coordinate system for a Graphics object is CoordinateSystem.TEXT, which means that as the x and y values in a Point object increase, the text (or bitmap or control) proceeds to the right horizontally and down vertically.
To associate a coordinate system with the Graphics object, use the setCoordinateSystem method, as follows:
Graphics gr = this.createGraphics();
gr.setCoordinateSystem(CoordinateSystem.ANISOTROPIC);
The following table lists the coordinate systems that you can associate with the Graphics object and describes the direction in which drawing proceeds as the x and y axes defined in a Point object increase.
Coordinate System | Icreasing x-axis | Increasing y-axis |
CoordinateSystem.TEXT | Right | Down |
CoordinateSystem.LOMETRIC | Right | Up |
CoordinateSystem.HIMETRIC | Right | Up |
CoordinateSystem.LOENGLISH | Right | Up |
CoordinateSystem.HIENGLISH | Right | Up |
CoordinateSystem.TWIPS | Right | Up |
CoordinateSystem.ISOTROPIC | User-defined | User-defined |
CoordinateSystem.ANISOTROPIC | User-defined | User-defined |
For more information, see: