Graphics and painting
paint() methods
So, what can we DO in the paint() or paintComponent()
methods? Pretty much anything that's available in the Graphics
class, and then some.
class Graphics and other useful helper classes
-
Graphics - helps manage drawing on the screen for GUI applications and
applets.
- Keeps track of state information like current font, current color,
the Component object being drawn on, and more
- Has methods for drawing various kinds of shapes (lines, ovals,
polygons, rectangles, etc) as well as strings.
- Also has methods for setting the font, the color, the current
clipping area, the paint mode, and other status information
-
Color - used for specifying colors in components and drawings
-
Font - specify fonts used in Graphics drawings
-
FontMetrics - abstract class. Encapsulates information and
properties about the rendering of a font on screen
-
Polygon - helper class for representing information about Polygons
- Stores a list of (x,y) coordinate pairs, representing vertices of a
polygon
- Several Graphics class methods are for drawing polygons -
drawPolygon(), drawPolyLine,
fillPolygon. There are versions of these last two that take
a Polygon object as a parameter.
Java2D
The Java2D API provides advanced graphics capabilities, for more detailed
and complex two-dimensional drawing.
Java 2D
API -- for an overview, see this page on the Java web site.
A
Java-2D Tutorial
See the last two chapter 12 examples -- these illustrate some sample uses
of Graphics2D methods draw() and fill(), along
with some of the Java2D shape types and drawing options.