In these supplements we look at the old and the new in Java graphics
- AWT - We first give present an overview of
graphics with the basic AWT. This can help to understand the basics
on which Swing and Java2D are built. Also, you might need to debug
or upgrade an older program or need to do graphics on a minimal
platform without Java2D.
- Java2D - The second part of this supplement
section looks at programming with Java2D. Java2D provides lots
of advanced graphical tools for drawing, text and image display.
Note: The user
interface examples discussed in Chapter
6: Java and in Chapter
7: Java use Swing and are a big step up in functionality and
esthetics over basic AWT. However, they are still fairly basic and
unadorned. In Chapter 7:
Supplements we discussion ways to enhance the appearance of
the Swing components and layouts.
An essential and very popular part of Java has always been its
graphical user interface capabilities. Applets, for example, were
intended to act as interactive mini-programs within the browser
environment and they needed not only to draw pictures and graphs
but also to provide for user input and control.
The graphics in versions 1.0 and 1.1 were very limited. Since version
1.2, the standard Java kit provides a far more capable and elaborate
set of graphics classes (javax.swing.*
) than the earlier versions. The Swing classes, however, still build
upon the lower level classes of the original java.awt.*
graphics classes. So it can be of some interest to know more about
the AWT (A Windows Toolkit.)
In this section we give a brief introduction to AWT graphics and
user interface development. This provides a background for the Swing
system but also, since many people still use browsers with a version
1.1 JVM, you might want to program some of your applets with only
the AWT classes so that they can work with as many users as possible.
The pages here discuss:
- Basics of the AWT - component
context class, drawing commands, and the drawing coordinate system.
- Simple Drawing - the essentials
of graphics drawing methods
- Text Drawing - drawing text with
different sizes and fonts.
We will continue in the Chapter
7 : Supplements : AWT- Part 2 section with additional information
on building program interfaces with the AWT.
This section provides a brief overview of the Java2D set of graphics
tools that became available with version 1.2. Java2D provides a
vast increase in graphical capabilities compared to the basic tools
available in the standard AWT graphics context.
We give a brief introduction and demonstration applets on the several
- Java2D introduction
- Shapes & Areas - rather than drawing
each line segment of a particular form, in Java2D a shape object
is created and then it draws itself in one operation.
- Transforms - affine transformations
provide for translations, rotations, scaling and skewing of the
- Strokes & Painting - control
line thicknesses, the endpoints, dashed form etc.
- Gradients&Textures -
shapes can be filled with gradient colors and image textures.
- Text - Java2D provides lots of text
capabilities and you could even create a full text editor from
scratch. Here we just look at how to vary the attributes of characters
in a string and how to give them a textured filling.
Most recent update: Oct. 3, 2005