Graphics 2D Posted on: December 14, 2008 at 12:00 AM
Clip is an art which can be an image, graphics, picture, photograph, video or any illustration.
Show Clippings Clip is an art which can be an image, graphics, picture, photograph, video or
We are providing you an example where we will show you the clippings.
In the given example, we have defined two buttons clip1 and clip2 to
perform two actions. On clicking clip1, a Rectangle2D class shows the clip of rectangular
area and on clicking clip2, Rectangle class (subclass of Rectangle2D) shows
a rectangle inside the rectangular area.
Noise Image in Graphics This Java Tutorial is all about creating Images with the use of graphics in
Java. For this we have to import awt and swing package in our Java code.
Event Dispatcher Thread In the tutorial Java Event Dispatcher thread in Graphics, we'll illustrate
you how to handle events in graphics using Java.
How to create Animation This section illustrates you how to create Animation. We are proving you an example defining a static variable DELAY of
integer type. The object of Insets class is provides the representation of the
Color Composite Example Composition is the process of combining two images. We are providing you an
example. The Ellipse2D.Float class provides an ellipse defining
values of float type.
Bouncing Thread Example In this section, we are going to develop a small Java Graphics application
that creates a ball which bounce with the help of thread
Use Alpha values to draw in Layers An alpha object produces the alpha value which changes with time
specified by the parameters of the alpha object. The alpha value is the
graphics state parameter that is used to composite objects to the existing page.
Show Alpha Value and Alpha Rules To give blending and transparency
effects with graphics and images and the alpha values, the class AlphaComposite
is used. An alpha value of 0.0f
makes the source disappear and 1.0f make it completely opaque.
Gradient Color Example Gradient Color is a tool bar which consists of different shades of color. We
are providing you an example which shows the Gradient Color.
How to show Rainbow Colors The Rainbow consists of seven colors known as VIBGYOR i.e. violet,
indigo, blue, green, yellow, orange and red color. We are providing you an
example which shows all the seven colors of rainbow.
Show XOR Mode XOR or Exclusive Or returns true only if both its operands have different values. The XOR shows the
uncommon part. We are providing you an example which shows the XOR mode.
Simple Basic Stroke Example The stylistic representation of the outline for the specified shape has been
given by the interface Stroke. To outline the specified shape rendered
with an object of Graphics2D, we have used the BasicStroke class.
Draw Dashed Oval To give the stylistic and impressive representation of the
outline, we have used the class BasicStroke. This class has
been given by the interface Stroke.
Show Stroke with Effect The interface Stroke gives the stylish way of representing the
outlines. To show the effect, class GradientPaint is used which fills the
specified figure in a color gradient pattern.
Outlining the font By outlining the font , we make the characters more stylish and impressive.
We are providing you an example which outlines the text.
Move Curve Control Point The Control points are the points on a curve which are used to change the shape and angle of the curve.
On stretching and rotating the control
point, the shape of the curve and the angle of a curve manipulates.
Simple Font Paint Example A font is a specific style of displaying characters. It describes the design,
size, appearance, weight, and spacing of a character. It is the combination of pitch and
Clip of image To show the image clip, we have used Ellipse2D class to show the oval
shape in an image. To give the path with straight line, we have used the class
GeneralPath. The AffineTransform class allows translation, shearing,
scaling, rotation etc.
Show Oval Icons An icon is an image that shows some concept or specific entity with meaning for the user. To show Oval Icons, we have used the class Container.
Display the Shadow of the string To display the shadow, we have used the class GradientPaint to draw a box. The g.setStroke(new
BasicStroke(15)) draw the wide lines.
Simple Gradient Paint Example A gradient refers to a colored strip with two defined endpoints. Both the end
points are defined with different color.
Round gradient Paint Example The radial gradient defines a color at a point, and blends into another color. We are providing you an example
which displays the radial gradient.
Another Example of Gradient Paint This section shows you the gradient Paint on rounded corner rectangle. A gradient is like a colored strip. It is created by specifying a
color at one point and another color at another point.
Show Text effect Text effect gives the stylistic way to design headings. To rotate the text, we
AffineTransform class that defines
different properties like rotation, translation, scaling and shearing etc.
Text Texture Example Texture refers to the roughness of the smoothness of a work of art. The way
in which you paint involves texture. A texture is a bitmap image applied
to the surface in computer graphics.
Show Graphics on full Screen To display the graphics, we have used the class DisplayMode which
provides the bit
depth, height, width, and refresh rate of a GraphicsDevice.
Show String in Oval To show a string in oval, we are providing you an example. A font 'Book
Antiqua' is defined to display the string 'WELCOME'.
To render the
particular font on the screen, we have used the class FontMetrics.
Display Different Fonts A font is a specific style of displaying characters. It describes the design,
size, appearance, weight, and spacing of a character. It is the combination of
pitch and spacing.
How to display the font in center To display the font in center, the method paint()
is defined. The Font class defines the font 'Monotype 'Corsiva'. The class
FontRenderContext measures the text.
Font Derivation Font derivation refers to the different styles provided by the font. The method deriveFont()
provides different styles to the characters.
Draw a Mandelbrot A Mandelbrot is a collection of points in the plane whose boundary forms a
fractal. It is having a complicated structure, which does not simplify at any given
Show Icon Displayer
An icon is an image, picture, or representation. To display the icon, we have defined an image. The class
responsible to paint the icons from Images. The MediaTracker preloads the
images that are created from a URL,
filename or byte array.
Show Calendar Icon An icon is a pictorial image used in a graphical user interface to represent
a program, a command, a link to a Web page, etc. To show calendar icon, we have
used the class Calendar.
Icon showing Color Gradient A color gradient consisting of two or more colors blending together. To
display the icon, we have defined the height and width of an image.
Icon Changes at runtime To create an icon, we have defined Icon class which provides three methods getIconWidth(),
getIconHeight() and paintIcon(). We have defined two sliders using JSlider class to show the changes related to
height and width of the icon.
Crop Image To crop an image, an image is defined inside the class folder. The
class ImageIcon calls its method getImage() which returns the specified image.
Generate Image Files
This section illustrates you how to generate image files. For this, we have
used the class ImageIO which provides methods for locating ImageReaders and
Show Image Scale To show scales of Image, an image is defined inside the class folder and
calls the ImageIcon class to return the image. The Insets class shows the border
of a container which specifies the space leave at each of its edges.
Display Image using
Toolkit.getImage() To display the image, put an image into the folder where the class is
specified. Class URL defines the resource. A resource can be a file or a
How to flip image To reverse the image, an image is put into the folder where class is specified. The getDefaultToolkit() method of
ToolKit class provides the default toolkit. The method getImage() of
class ToolKit returns an image.
Show Image Effect To show Image effects, we have defined three matrix: RED_MATRIX,
GREEN_MATRIX, BLUE_MATRIX which shows colors.
Show Other Image Effects To show image effects like sharpen, blur, show edge, reset ,etc, we have
create radio buttons on which the action will be performed by calling ActionListener
Affine Transform Example The sequences of translations, scales,
flips, rotations, and shears are provided by the class AffineTransform. To show
shearing, we are providing
you an example.
Use of Image I/O library The ImageIO class provides the method to read and write image. We are providing you an example which copies the specified input file into the
TextHitInfo Example In this section, we are providing you an example based on class TextHitInfo.
In the given example, when you click the element of the string, TextHitInfo class will displayed
the position of character on the console.
Break a Line for text layout In this section, we are providing you an example to break a line. To break
down the text into lines, the class LineBreakMeasurer is used. The class Hashtable
maps keys to values.
Show Image Reader and
Image Writer by MIME Type
To show the image reader and image writer by MIME Type, we have used ImageIO class
of the package javax.imageio.*. The ImageIO class provides the methods for locating ImageReaders and
Show Transparent Text To draw the text, Font class is used. To show transparency over the
specified text, the class AlphaComposite is used which shows the
transparency effects with graphics.
Draw text like a curve To draw the text, we have used the Font class which represents the
font to render the text. The method getFontRenderContext() of class Graphics2D
get the rendering context of the font specified.
Show Textured Paint Texture refers to the roughness of the smoothness of a work of art. The way
in which you paint involves texture. We are providing you an example that will
show the textured paint.
Show Different Strokes To give the the impressive and stylistic outline, class BasicStroke is
used. The value passed in the constructor of the class BasicStroke shows
the thickness of outline.
Show General Path This section illustrates you how to create GeneralPath. We have used
the class GeneralPath to create three different shapes. For this, we have
create three objects of class GeneralPath i.e, path1, path2, path3.
Mouse Drag and Drop To draw a figure using drag and drop, we have used Rectangle2D class
to draw a rectangle. This rectangle has been shown on the frame. When you drag
the rectangle and move, a number of figures will be drawn connected to each
Draw Polygon in Graphics A polygon is a closed path or circuit which is made by joining line segments.
In polygon, each line segment intersects exactly two others line segments. To
draw a polygon, we have used the Polygon class.
Draw An Arc in Graphics An arc of a circle is a segment of the circumference of the circle. To draw
an arc, class Arc2D is used. To give the stylistic and impressive way to the outline of arc, we have used BasicStroke class.
Draw Ellipse in Rectangle To draw an Ellipse inside the rectangle, we have defined two classes Rectangle2D
and Ellipse2D of package java.awt.geom.*. These
classes provides a rectangle and a circle respectively.
Draw a Triangle using a Line2D To draw a triangle, we are using Line2D class of package
This class provides a line segment in (x, y) coordinate space. We have draw
three line segments using the class Line2D to create a triangle.
Show Color Components To show color components, we have used the class DirectColorModel. The
DirectColorModel class shows pixel values that represent RGB
color and alpha information and pack into a single int, short, or byte
Draw Grids To draw the grids, we have defined rows and columns. The method g.drawLine(0, k *
heightOfRow, width, k * heightOfRow) draws the number of rows.
Different Line Styles To show different styles of line, we have used BasicStroke class. The class
BasicStroke provides several line drawing attributes: the line width, the dash
pattern, the end cap style for the line, and the join style for the line.
Change Color and Font of text This section illustrates you how to change color and font of text using TextAttributes
class. A string is defined and the class AttributedString holds
Layout text along a line using LineMetrics This section illustrates you how to layout text along a line. For this, class
LineMetrics is used which layouts the text along a line. The Font
class represents the font.
Show Coordinates In this section, we are going to display a frame where we have draw the grid.
As the user move or click the cursor with the mouse over the grid, a label
displays the location of cursor, i.e., shows coordinates with respect to
x-axis and y-axis.