<s>
Java	B-Language
2D	I-Language
is	O
an	O
API	B-General_Concept
for	O
drawing	O
two-dimensional	O
graphics	O
using	O
the	O
Java	B-Language
programming	I-Language
language	I-Language
.	O
</s>
<s>
Every	O
Java	B-Language
2D	I-Language
drawing	O
operation	O
can	O
ultimately	O
be	O
treated	O
as	O
filling	O
a	O
shape	O
using	O
a	O
paint	O
and	O
compositing	O
the	O
result	O
onto	O
the	O
screen	B-Device
.	O
</s>
<s>
The	O
Java	B-Language
2D	I-Language
API	B-General_Concept
and	O
its	O
documentation	O
are	O
available	O
for	O
download	O
as	O
a	O
part	O
of	O
JDK	O
6	O
.	O
</s>
<s>
Java	B-Language
2D	I-Language
API	B-General_Concept
classes	O
are	O
organised	O
into	O
the	O
following	O
packages	O
in	O
JDK	O
6	O
:	O
</s>
<s>
The	O
main	O
package	O
for	O
the	O
Java	B-Language
Abstract	B-Language
Window	I-Language
Toolkit	I-Language
.	O
</s>
<s>
The	O
Java	B-Language
standard	O
library	O
of	O
two	O
dimensional	O
geometric	O
shapes	O
such	O
as	O
lines	O
,	O
ellipses	O
,	O
and	O
quadrilaterals	O
.	O
</s>
<s>
The	O
library	O
for	O
manipulating	O
glyphs	B-Application
in	O
Java	B-Language
.	O
</s>
<s>
These	O
objects	O
are	O
a	O
necessary	O
part	O
of	O
every	O
Java	B-Language
2D	I-Language
drawing	O
operation	O
.	O
</s>
<s>
A	O
shape	O
in	O
Java	B-Language
2D	I-Language
is	O
a	O
boundary	O
which	O
defines	O
an	O
inside	O
and	O
an	O
outside	O
.	O
</s>
<s>
Pixels	B-Algorithm
inside	O
the	O
shape	O
are	O
affected	O
by	O
the	O
drawing	O
operation	O
,	O
those	O
outside	O
are	O
not	O
.	O
</s>
<s>
Trying	O
to	O
fill	O
a	O
straight	O
line	O
segment	O
will	O
result	O
in	O
no	O
pixels	B-Algorithm
being	O
affected	O
,	O
as	O
such	O
a	O
shape	O
does	O
not	O
contain	O
any	O
pixels	B-Algorithm
itself	O
.	O
</s>
<s>
Instead	O
,	O
a	O
thin	O
rectangle	O
must	O
be	O
used	O
so	O
that	O
the	O
shape	O
contains	O
some	O
pixels	B-Algorithm
.	O
</s>
<s>
A	O
paint	O
generates	O
the	O
colors	O
to	O
be	O
used	O
for	O
each	O
pixel	B-Algorithm
of	O
the	O
fill	O
operation	O
.	O
</s>
<s>
The	O
simplest	O
paint	O
is	O
,	O
which	O
generates	O
the	O
same	O
color	O
for	O
all	O
pixels	B-Algorithm
.	O
</s>
<s>
During	O
any	O
drawing	O
operation	O
,	O
there	O
is	O
a	O
source	O
(	O
the	O
pixels	B-Algorithm
being	O
produced	O
by	O
the	O
paint	O
)	O
and	O
a	O
destination	O
(	O
the	O
pixels	B-Algorithm
already	O
onscreen	O
)	O
.	O
</s>
<s>
Normally	O
,	O
the	O
source	O
pixels	B-Algorithm
simply	O
overwrite	O
the	O
destination	O
pixels	B-Algorithm
,	O
but	O
the	O
composite	O
allows	O
this	O
behavior	O
to	O
be	O
changed	O
.	O
</s>
<s>
The	O
composite	O
,	O
given	O
the	O
source	O
and	O
destination	O
pixels	B-Algorithm
,	O
produces	O
the	O
final	O
result	O
that	O
ultimately	O
ends	O
up	O
onscreen	O
.	O
</s>
<s>
The	O
most	O
common	O
composite	O
is	O
,	O
which	O
can	O
treat	O
the	O
pixels	B-Algorithm
being	O
drawn	O
as	O
partially	O
transparent	O
,	O
so	O
that	O
the	O
destination	O
pixels	B-Algorithm
show	O
through	O
to	O
some	O
degree	O
.	O
</s>
<s>
To	O
fill	O
a	O
shape	O
,	O
the	O
first	O
step	O
is	O
to	O
identify	O
which	O
pixels	B-Algorithm
fall	O
inside	O
the	O
shape	O
.	O
</s>
<s>
These	O
pixels	B-Algorithm
will	O
be	O
affected	O
by	O
the	O
fill	O
operation	O
.	O
</s>
<s>
Pixels	B-Algorithm
that	O
are	O
partially	O
inside	O
and	O
partially	O
outside	O
the	O
shape	O
may	O
be	O
affected	O
to	O
a	O
lesser	O
degree	O
if	O
anti-aliasing	B-Algorithm
is	O
enabled	O
.	O
</s>
<s>
The	O
paint	O
is	O
then	O
asked	O
to	O
generate	O
a	O
color	O
for	O
each	O
of	O
the	O
pixels	B-Algorithm
to	O
be	O
painted	O
.	O
</s>
<s>
In	O
the	O
common	O
case	O
of	O
a	O
solid-color	O
fill	O
,	O
each	O
pixel	B-Algorithm
will	O
be	O
set	O
to	O
the	O
same	O
color	O
.	O
</s>
<s>
The	O
composite	O
takes	O
the	O
pixels	B-Algorithm
generated	O
by	O
the	O
paint	O
and	O
combines	O
them	O
with	O
the	O
pixels	B-Algorithm
already	O
onscreen	O
to	O
produce	O
the	O
final	O
result	O
.	O
</s>
<s>
Every	O
Java	B-Language
2D	I-Language
operation	O
is	O
subject	O
to	O
a	O
transform	B-Algorithm
,	O
so	O
that	O
shapes	O
may	O
be	O
translated	O
,	O
rotated	O
,	O
sheared	O
,	O
and	O
scaled	O
as	O
they	O
are	O
drawn	O
.	O
</s>
<s>
The	O
active	O
transform	B-Algorithm
is	O
most	O
often	O
the	O
identity	O
transform	B-Algorithm
,	O
which	O
does	O
nothing	O
.	O
</s>
<s>
Filling	O
using	O
a	O
transform	B-Algorithm
can	O
be	O
viewed	O
as	O
simply	O
creating	O
a	O
new	O
,	O
transformed	O
shape	O
and	O
then	O
filling	O
that	O
shape	O
.	O
</s>
<s>
In	O
addition	O
to	O
the	O
fill	O
operation	O
,	O
Java	B-Language
2D	I-Language
provides	O
a	O
draw	O
operation	O
.	O
</s>
<s>
For	O
instance	O
,	O
an	O
infinitely	O
thin	O
line	O
segment	O
(	O
with	O
no	O
interior	O
)	O
might	O
be	O
stroked	O
into	O
a	O
one-pixel-wide	O
rectangle	O
.	O
</s>
<s>
The	O
stroke	O
implementation	O
provided	O
with	O
Java	B-Language
2D	I-Language
implements	O
the	O
outline	O
rules	O
described	O
above	O
,	O
but	O
a	O
custom-written	O
stroke	O
could	O
produce	O
any	O
shape	O
it	O
wished	O
.	O
</s>
<s>
Conceptually	O
,	O
drawing	O
a	O
straight	O
black	O
line	O
in	O
Java	B-Language
2D	I-Language
can	O
be	O
thought	O
of	O
as	O
creating	O
a	O
line	O
segment	O
,	O
transforming	O
it	O
according	O
to	O
the	O
current	O
transform	B-Algorithm
,	O
stroking	O
it	O
to	O
create	O
a	O
thin	O
rectangle	O
,	O
querying	O
this	O
shape	O
to	O
compute	O
the	O
pixels	B-Algorithm
being	O
affected	O
,	O
generating	O
the	O
pixels	B-Algorithm
using	O
,	O
and	O
then	O
compositing	O
the	O
results	O
onto	O
the	O
screen	B-Device
.	O
</s>
<s>
Java	B-Language
2D	I-Language
therefore	O
optimizes	O
common	O
drawing	O
operations	O
so	O
that	O
many	O
of	O
these	O
steps	O
can	O
be	O
skipped	O
.	O
</s>
<s>
Java	B-Language
2D	I-Language
performs	O
the	O
minimum	O
amount	O
of	O
work	O
necessary	O
to	O
make	O
it	O
seem	O
as	O
if	O
it	O
is	O
performing	O
all	O
of	O
these	O
steps	O
for	O
each	O
operation	O
,	O
therefore	O
retaining	O
both	O
great	O
flexibility	O
and	O
high	O
performance	O
.	O
</s>
<s>
For	O
simplicity	O
,	O
the	O
textual	O
examples	O
provided	O
in	O
this	O
article	O
have	O
assumed	O
that	O
the	O
screen	B-Device
is	O
the	O
destination	O
device	O
.	O
</s>
<s>
However	O
,	O
the	O
destination	O
can	O
be	O
anything	O
,	O
such	O
as	O
a	O
printer	O
,	O
memory	O
image	O
,	O
or	O
even	O
an	O
object	O
which	O
accepts	O
Java	B-Language
2D	I-Language
graphics	O
commands	O
and	O
translates	O
them	O
into	O
vector	O
graphic	O
image	O
files	O
.	O
</s>
<s>
Since	O
Java	B-Language
SE	O
6	O
,	O
Java2D	B-Language
and	O
OpenGL	B-Application
have	O
become	O
interoperable	O
,	O
allowing	O
,	O
for	O
example	O
,	O
the	O
drawing	O
of	O
animated	O
3D	O
graphics	O
instead	O
of	O
icons	O
on	O
a	O
Button	O
(	O
see	O
JOGL	O
)	O
.	O
</s>
