FACTOID # 73: The ten most generous countries are all in Europe.
 
 Home   Encyclopedia   Statistics   Countries A-Z   Flags   Maps   Education   Forum   FAQ   About 
 
WHAT'S NEW
RECENT ARTICLES
More Recent Articles »
 

Encyclopedia > Java 2D

In computing, Java 2D is an API for drawing two-dimensional graphics using the Java programming language. Every Java 2D drawing operation can ultimately be treated as filling a shape using a paint and compositing the result onto the screen. Originally, the word computing was synonymous with counting and calculating, and a science that deals with the original sense of computing mathematical calculations. ... API may refer to: In computing, application programming interface In petroleum industry, American Petroleum Institute In education, Academic Performance Index This page concerning a three-letter acronym or abbreviation is a disambiguation page — a navigational aid which lists other pages that might otherwise share the same title. ... Dimension (from Latin measured out) is, in essence, the number of degrees of freedom available for movement in a space. ... Computer graphics (CG) is the field of visual computing, where one utilizes computers both to generate visual images synthetically and to integrate or alter visual and spatial information sampled from the real world. ... Java is an object-oriented programming language developed by James Gosling and colleagues at Sun Microsystems in the early 1990s. ... Nineteen inch (48 cm) CRT computer monitor A computer display, monitor or screen is a computer peripheral device capable of showing characters and/or still or moving images generated by a computer and processed by a graphics card. ...

Contents


Basic Concepts

These objects are a necessary part of every Java 2D drawing operation.


Shapes

A shape in Java 2D is an infinitely thin boundary which defines an inside and an outside. Pixels inside the shape are affected by the drawing operation, those outside are not. The word Boundary has a variety of meanings. ... A pixel (pix, 1932 abbreviation of pictures, coined by Variety headline writers + element) is one of the many tiny dots that make up the representation of a picture in a computers memory. ...


Trying to fill an infinitely thin, straight line segment will result in no pixels being affected, as such a shape does not contain any pixels. Instead, a thin rectangle must be used so that the shape contains some pixels. In mathematics, a line segment is a part of a line that is bounded by two end points. ... In geometry, a rectangle is defined as a quadrilateral polygon in which all four angles are right angles. ...


Paints

A paint generates the colors to be used for each pixel of the fill operation. The simplest paint is java.awt.Color, which generates the same color for all pixels. More complicated paints may produce gradients, images, or indeed any combination of colors. Filling a circular shape using the color yellow results in a solid yellow circle, while filling the same circular shape using a paint that generates an image produces a circular cutout of the image. Color is an important part of the visual arts. ... For images in Wikipedia, see Wikipedia:Images. ...


Composites

During any drawing operation, there is a source (the pixels being produced by the paint) and a destination (the pixels already onscreen). Normally, the source pixels simply overwrite the destination pixels, but the composite allows this behavior to be changed.


The composite, given the source and destination pixels, produces the final result that ultimately ends up onscreen. The most common composite is java.awt.AlphaComposite, which can treat the pixels being drawn as partially transparent, so that the destination pixels show through to some degree.


Filling

To fill a shape, the first step is to identify which pixels fall inside the shape. These pixels will be affected by the fill operation. Pixels that are partially inside and partially outside the shape may be affected to a lesser degree if anti-aliasing is enabled. In digital signal processing, anti-aliasing is the technique of minimizing aliasing (jagged or blocky patterns) when representing a high-resolution signal at a lower resolution. ...


The paint is then asked to generate a color for each of the pixels to be painted. In the common case of a solid-color fill, each pixel will be set to the same color.


The composite takes the pixels generated by the paint and combines them with the pixels already onscreen to produce the final result.


Advanced Objects

These objects can be viewed as performing their duties in terms of the simpler objects described above.


Transform

Every Java 2D operation is subject to a transform, so that shapes may be translated, rotated, sheared, and scaled as they are drawn. The active transform is most often the identity transform, which does nothing. In geometry, an affine transformation or affine map (from the Latin, affinis, connected with) between two vector spaces consists of a linear transformation followed by a translation: In the finite-dimensional case each affine transformation is given by a matrix A and a vector b, which can be written as...


Filling using a transform can be viewed as simply creating a new, transformed shape and then filling that shape.


Stroke

In addition to the fill operation, Java 2D provides a draw operation. While fill draws the interior of a shape, draw draws its outline. The outline can be as simple as a thin line, or as complicated as a dashed line with each dash having rounded edges.


The object responsible for generating the outline is the stroke. Given an input shape, the stroke produces a new shape representing its outline. For instance, an infinitely thin line segment (with no interior) might be stroked into a one-pixel-wide rectangle.


A draw operation can therefore be described as creating a new, stroked object and then filling that object.


Technically speaking, the stroke is only required to accept an input shape and produce a new shape. The stroke implementation provided with Java 2D implements the outline rules described above, but a custom-written stroke could produce any shape it wished.


Optimizations

Conceptually, drawing a straight black line in Java 2D can be thought of as creating a line segment, transforming it according to the current transform, stroking it to create a thin rectangle, querying this shape to compute the pixels being affected, generating the pixels using java.awt.Color.BLACK, and then compositing the results onto the screen.


However, performing this entire sequence of steps for each drawing operation would be very inefficient. Java 2D therefore optimizes common drawing operations so that many of these steps can be skipped. If the paint is a simple solid color, for instance, there is no need to actually command it to generate a list of colors to be painted. Likewise, if the default fully-opaque composite is in use, actually asking it to perform the compositing operation is unnecessary and would waste effort.


Java 2D performs the minimum amount of work necessary to make it seem as if it is performing all of these steps for each operation, therefore retaining both great flexibility and high performance.


Destination

For simplicity, the examples in this article have assumed that the screen is the destination device. However, the destination can be anything, such as a printer, memory image, or even an object which accepts Java 2D graphics commands and translates them into vector graphic image files. Steam Locomotive 7646 as a vector, originally Windows Metafile (converted to GIF for display here). ...


External links


 

COMMENTARY     


Share your thoughts, questions and commentary here
Your name
Your location
Your comments
Please enter the 5-letter protection code


Lesson Plans | Student Area | Student FAQ | Reviews | Press Releases |  Feeds | Contact
The Wikipedia article included on this page is licensed under the GFDL.
Images may be subject to relevant owners' copyright.
All other elements are (c) copyright NationMaster.com 2003-5. All Rights Reserved.
Usage implies agreement with terms.