Java Reference
In-Depth Information
developing richer GUIs through line art (also known as vector graphics—see
ht-
tp://en.wikipedia.org/wiki/Vector_graphics
), text, and images.
Java 2D is implemented by various types located in the
java.awt
and
java.awt.image
packages, and by the Java 2D-specific
java.awt.color
,
java.awt.font
,
java.awt.geom
,
java.awt.image.renderable
, and
java.awt.print
packages.
This section introduces Java 2D by first presenting the
java.awt
package's
GraphicsEnvironment
,
GraphicsDevice
,and
GraphicsConfiguration
classes. It then explores the
Graphics2D
class followed by Java 2D's support for
shapes and buffered images. (I don't explore text or printing, for brevity.)
GraphicsEnvironment, GraphicsDevice, and GraphicsConfiguration
Java2Dprovidesa
GraphicsEnvironment
classthatapplicationscanusetolearn
about their graphics environments (e.g., available font family names and graphics
devices) and perform specialized tasks (e.g., register a font or create a
Graphics2D
instance for drawing into a buffered image).
Before you can use
GraphicsEnvironment
, you need to obtain an instance of
thisclass.Accomplishthistaskbyinvoking
GraphicsEnvironment
's
Graphic-
sEnvironment getLocalGraphicsEnvironment()
class method to return
the platform's
GraphicsEnvironment
instance, as follows:
GraphicsEnvironment
ge
=
GraphicsEnviron-
ment.getLocalGraphicsEnvironment();
GraphicsEnvironment
's Java documentation states that the returned
Graph-
icsEnvironment
instance's resources might be local or located on a remote ma-
chine. For example, Linux platforms let users use Secure Shell (see
ht-
tp://en.wikipedia.org/wiki/Secure_Shell
)
to run GUI applications on
another machine and view the GUI on the local machine. (If you're interested in
learning more about this, check out “X Over SSH2 - A Tutorial” [
ht-
Onceanapplicationhasa
GraphicsEnvironment
instance,itcancall
Graph-
icsEnvironment
's String[] getAvailableFontFamilyNames() method to enumerate
font family names (such as Arial), as
Listing 7-7
demonstrates.
Listing 7-7
. Enumerating font family names