Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
An appealing feature of Java is its graphics support, which enables you to visually enhance your applications. We now introduce one of Java’s graphical capabilities—drawing lines. It also covers the basics of creating a window to display a drawing on the computer screen.
To draw in Java, you must understand Java’s coordinate system (Fig. 4.17), a scheme for identifying points on the screen. By default, the upper-left corner of a GUI component has the coordinates (0, 0). A coordinate pair is composed of an x-coordinate (the horizontal coordinate) and a y-coordinate (the vertical coordinate). The x-coordinate is the horizontal location moving from left to right. The y-coordinate is the vertical location moving from top to bottom. The x-axis describes every horizontal coordinate, and the y-axis every vertical coordinate.