by Dinesh Thakur

The Java2D API provides advanced two-dimensional graphics capabilities for programmers who require detailed and complex graphical manipulations. The API includes features for processing line art, text and images in packages java.awt, java.awt.image, java.awt.color, java.awt.font. java.awt.geom, java.awt.print and java.awt.image.renderable.



 
by Dinesh Thakur

The variable map is which allows you to assign design attributes of the object type source AttributedString. Through this variable may change any aspect of the font . TextAttribute example shown the code as follows:

 
by Dinesh Thakur

This code can be seen as built a clipping path with the text area of the word " Dinesh Thakur " located in the middle of the window. In the drawn area can be seen as the image is painted behind the chain. As seen, the effect is very colorful and easy to perform.

 

 
by Dinesh Thakur

This code can be seen as built a clipping path with the content of the text area of the word "Java " located in the middle of the window.In the drawn area can be seen as the image is painted behind the chain. As seen, the effect is very colorful and easy to perform.



 
by Dinesh Thakur

With this code we will study how text is drawn on a any image.

 
by Dinesh Thakur

much more powerful mechanism for drawing text is provided  the TextLayout class.This class not only allows you to draw text in a similar way  to as was done be fore but also provides a number of methods that  let youk now what is specific to draw features.

 
by Dinesh Thakur

In this example we show how the Set operations going to make a Addition of 2 circles. An example show the code below:

 
by Dinesh Thakur

In this example we show how the Set operations going to make a Intersection of 2 circles . Intersection examples how the code as follows:

 
by Dinesh Thakur

In this example we show how the Set operations going to make a Subtraction of 2 circles . Subtraction examples how the code as follows:

 
by Dinesh Thakur

In this example we show how the Set operations going to make a union of 2 circles. Union exclusive (XOR ) examples how the code as follows:

 
by Dinesh Thakur

Another way is to build figures using GeneralPath class, which but also inherits from Shapeisan interface, but a class. This class allows  define a shape by a sequence oflines that can be established through  functions in the following table:

 
by Dinesh Thakur

Point2D class does not draw anything; it is the representation of points Java2D. But yes you can draw shapes from points. Following is at able that lists some of the Constructors and methods of Point2D class:

 
by Dinesh Thakur

CubicCurve2D which also shows the segments joining  the ends with the points control and the set together. An example of use appears in the following code, which also have highlighted the four reference points. The result can be seen in CubicCurve2D Java Example.



 
by Dinesh Thakur

The QuadCurve2D class lets build a curved segment based on mathematical equations. The curve generated is also called curve quadratic Bezier and based on a very simple idea is to establish two points that define the ends of a curved segment and a third point, called checkpoint that allows "stretching" more or less the curvature of the segment.

 
by Dinesh Thakur

The class allows Arc2D draw an arc of an ellipse or a circle. For this, first the rectangle that contains the ellipse whose arc you want to draw is defined ; then assuming that the center of the rectangle sets the point (0,0) of a Cartesian coordinate axis , the angles start and end are specified the arc in degrees . Finally , indicate whether you want to close the bow joining ends or not. This closure can be of three types :

 
by Dinesh Thakur

The ellipses or ovals are drawn by Ellipse2D class.This requires you defined to be a rectangle enclosing the boundaries between the ellipse.There the concept of a circle, so that it must be obtained by an ellipse enclosed in a square.

 
by Dinesh Thakur

Draw a straight line is one of the easiest things to do with Java2D. This is achieved through the Line2D class, whose constructor accepts four parameters, namely the coordinates of the start and end respectively.

 
by Dinesh Thakur

The class that is used to draw rectangles and squares is the Rectangle2D. The constructor specifies the first two parameters of the corner position upper left relative to the coordinate system of the window.