Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Java 2D
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Basic concepts== These objects are a necessary part of every Java 2D drawing operation. ===Shapes=== A ''shape'' in Java 2D is a boundary which defines an inside and an outside. [[Pixel]]s inside the shape are affected by the drawing operation, those outside are not. Trying to fill a straight [[line segment]] will result in no pixels being affected, as such a shape does not contain any pixels itself. Instead, a thin [[rectangle]] must be used so that the shape contains some pixels. ===Paints=== A ''paint'' generates the [[color]]s to be used for each pixel of the fill operation. The simplest paint is '''{{Javadoc:SE|package=java.awt|java/awt|Color|module=java.desktop}}''', which generates the same color for all pixels. More complicated paints may produce gradients, [[image]]s, 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. ===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 '''{{Javadoc:SE|package=java.awt|java/awt|AlphaComposite|module=java.desktop}}''', 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 [[Spatial anti-aliasing|anti-aliasing]] is enabled. 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.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)