
This discussion of dimensions in inches on the screen depends on the method named getScreenResolution() returning the correct value. The program was tested using JDK 1.2.2 under WinNT Workstation 4.0 However, in this case, the variations in color progress along and beyond a hypothetical line that is angled at 45 degrees to the horizontal. The color gradient in the lower right-hand circle also progresses from red to orange and back several times in a cyclic manner. The variations in color progress along and beyond a hypothetical line that is parallel to the horizontal axis.Ĭyclic gradient at 45 degrees to the horizontal The color gradient in the lower left-hand circle progresses from red to orange and back several times in a cyclic manner. Only that portion in between the beginning and the end points of the hypothetical line vary in color. Everything to the right of the end of the hypothetical line is the same color orange. In other words, everything to the left of the beginning of a hypothetical line is the same color red. The color gradient in the upper right-hand circle progresses from red on the left end of a hypothetical line to orange on the right end of a hypothetical line in an acyclic manner. The circles in the other three quadrants are filled with color gradients that progress from red to orange in different ways. For purpose of reference, it fills the circle in the upper left quadrant with solid red, exactly as in an earlier program. The program then draws one two-inch diameter circle in each quadrant. So far, this is very similar to the sample programs that I have explained in previous lessons. Then it draws a pair of X and Y-axes centered on the new origin. It translates the origin to the center of the Frame.

The program draws a four-inch by four-inch Frame on the screen. Thus some of the quality was lost in the process. Note that this screen shot was reduced to about seventy-percent of its original size in pixels. In this case, the Paint object is an instance of the GradientPaint class, which implements the interface named Paint.Ī significantly reduced screen shot of the output of this program is shown below. It illustrates the use of a Paint object to fill a Shape with a solid color. The name of this program is PaintGradient01. This will also be the topic of a subsequent lesson. The TexturePaint class can be used to fill a Shape with a tiled version of a BufferedImage object. The use of the GradientPaint class is the primary topic of this lesson. The gradient can also be caused to repeat in a cyclic fashion beyond the end points of the hypothetical line segment. The two colors can be stabilized beyond the end points of the hypothetical line segment. The two points describe a hypothetical line segment in user space. The gradient progresses from one specified color at one point in user space to a different specified color at a different point in user space. The GradientPaint class can be used to fill a Shape with a color gradient. The Color class can be used to fill a Shape object with a solid color.

In a previous lesson, I explained that the Java2D API in JDK 1.2.2 provides three classes that implement the Paint interface (and you can also define your own):
Java jxl colour constructor how to#
This lesson will show you how to fill a Shape with a color gradient, both cyclic and acyclic.

Invoke the fill() method on the Graphics2D object, passing a reference to the Shape object that you want to fill as a parameter.Invoke setPaint() on the Graphics2D object, passing a reference to an object of a class that implements the Paint interface as a parameter.I explained in an earlier lesson that if you want to fill a Shape object before you draw it, you can accomplish this with the following two steps: An earlier lesson showed you how to fill a Shape with a solid color. I also explained that without understanding the behavior of other classes and interfaces such as Shape, AffineTransform, GraphicsConfiguration, PathIterator, and Stroke, it is not possible to fully understand the inner workings of the Graphics2D class.Įarlier lessons have explained a number of Java 2D concepts, including Shape, AffineTransform, and PathIterator.īefore, I can explain the Stroke class, I need to explain how to fill a Shape in general. Understanding other classes also required Beginning with JDK 1.2, Graphics2D is the fundamental class for rendering two-dimensional shapes, text and images.

In an earlier lesson, I explained that the Graphics2D class extends the Graphics class to provide more sophisticated control over geometry, coordinate transformations, color management, and text layout.
