|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object![]()
![]()
![]()
java.awt.Graphics
, Graphics2D

public abstract class Graphics

The Graphics class is the abstract base class for
all graphics contexts that allow an application to draw onto
components that are realized on various devices, as well as
onto off-screen images.
A Graphics object encapsulates state information needed
for the basic rendering operations that Java supports. This
state information includes the following properties:
Component object on which to draw.
setXORMode(java.awt.Color)
).
Coordinates are infinitely thin and lie between the pixels of the output device. Operations that draw the outline of a figure operate by traversing an infinitely thin path between pixels with a pixel-sized pen that hangs down and to the right of the anchor point on the path. Operations that fill a figure operate by filling the interior of that infinitely thin path. Operations that render horizontal text render the ascending portion of character glyphs entirely above the baseline coordinate.
The graphics pen hangs down and to the right from the path it traverses. This has the following implications:
All coordinates that appear as arguments to the methods of this
Graphics object are considered relative to the
translation origin of this Graphics object prior to
the invocation of the method.
All rendering operations modify only pixels which lie within the
area bounded by the current clip, which is specified by a Shape
in user space and is controlled by the program using the
Graphics object. This user clip
is transformed into device space and combined with the
device clip, which is defined by the visibility of windows and
device extents. The combination of the user clip and device clip
defines the composite clip, which determines the final clipping
region. The user clip cannot be modified by the rendering
system to reflect the resulting composite clip. The user clip can only
be changed through the setClip or clipRect
methods.
All drawing or writing is done in the current color,
using the current paint mode, and in the current font.
Component
,
clipRect(int, int, int, int)
,
setColor(java.awt.Color)
,
setPaintMode()
,
setXORMode(java.awt.Color)
,
setFont(java.awt.Font)

| Constructor Summary | |
|---|---|
protected |
Graphics
Constructs a new Graphics object. |
| Method Summary | |
|---|---|
abstract void |
clearRect
Clears the specified rectangle by filling it with the background color of the current drawing surface. |
abstract void |
clipRect
Intersects the current clip with the specified rectangle. |
abstract void |
copyArea
Copies an area of the component by a distance specified by dx and dy. |
abstract Graphics |
create
Creates a new Graphics object that is
a copy of this Graphics object. |
Graphics |
create
Creates a new Graphics object based on this
Graphics object, but with a new translation and clip area. |
abstract void |
dispose
Disposes of this graphics context and releases any system resources that it is using. |
void |
draw3DRect
Draws a 3-D highlighted outline of the specified rectangle. |
abstract void |
drawArc
Draws the outline of a circular or elliptical arc covering the specified rectangle. |
void |
drawBytes
Draws the text given by the specified byte array, using this graphics context's current font and color. |
void |
drawChars
Draws the text given by the specified character array, using this graphics context's current font and color. |
abstract boolean |
drawImage
Draws as much of the specified image as is currently available. |
abstract boolean |
drawImage
Draws as much of the specified image as is currently available. |
abstract boolean |
drawImage
Draws as much of the specified image as has already been scaled to fit inside the specified rectangle. |
abstract boolean |
drawImage
Draws as much of the specified image as has already been scaled to fit inside the specified rectangle. |
abstract boolean |
drawImage
Draws as much of the specified area of the specified image as is currently available, scaling it on the fly to fit inside the specified area of the destination drawable surface. |
abstract boolean |
drawImage
Draws as much of the specified area of the specified image as is currently available, scaling it on the fly to fit inside the specified area of the destination drawable surface. |
abstract void |
drawLine
Draws a line, using the current color, between the points (x1, y1) and (x2, y2)
in this graphics context's coordinate system. |
abstract void |
drawOval
Draws the outline of an oval. |
abstract void |
drawPolygon
Draws a closed polygon defined by arrays of x and y coordinates. |
void |
drawPolygon
Draws the outline of a polygon defined by the specified Polygon object. |
abstract void |
drawPolyline
Draws a sequence of connected lines defined by arrays of x and y coordinates. |
void |
drawRect
Draws the outline of the specified rectangle. |
abstract void |
drawRoundRect
Draws an outlined round-cornered rectangle using this graphics context's current color. |
abstract void |
drawString
Draws the text given by the specified iterator, using this graphics context's current color. |
abstract void |
drawString
Draws the text given by the specified string, using this graphics context's current font and color. |
void |
fill3DRect
Paints a 3-D highlighted rectangle filled with the current color. |
abstract void |
fillArc
Fills a circular or elliptical arc covering the specified rectangle. |
abstract void |
fillOval
Fills an oval bounded by the specified rectangle with the current color. |
abstract void |
fillPolygon
Fills a closed polygon defined by arrays of x and y coordinates. |
void |
fillPolygon
Fills the polygon defined by the specified Polygon object with the graphics context's current color. |
abstract void |
fillRect
Fills the specified rectangle. |
abstract void |
fillRoundRect
Fills the specified rounded corner rectangle with the current color. |
void |
finalize
Disposes of this graphics context once it is no longer referenced. |
abstract Shape |
getClip
Gets the current clipping area. |
abstract Rectangle |
getClipBounds
Returns the bounding rectangle of the current clipping area. |
Rectangle |
getClipBounds
Returns the bounding rectangle of the current clipping area. |
Rectangle |
getClipRect
Deprecated. As of JDK version 1.1, replaced by getClipBounds(). |
abstract Color |
getColor
Gets this graphics context's current color. |
abstract Font |
getFont
Gets the current font. |
FontMetrics |
getFontMetrics
Gets the font metrics of the current font. |
abstract FontMetrics |
getFontMetrics
Gets the font metrics for the specified font. |
boolean |
hitClip
Returns true if the specified rectangular area might intersect the current clipping area. |
abstract void |
setClip
Sets the current clip to the rectangle specified by the given coordinates. |
abstract void |
setClip
Sets the current clipping area to an arbitrary clip shape. |
abstract void |
setColor
Sets this graphics context's current color to the specified color. |
abstract void |
setFont
Sets this graphics context's font to the specified font. |
abstract void |
setPaintMode
Sets the paint mode of this graphics context to overwrite the destination with this graphics context's current color. |
abstract void |
setXORMode
Sets the paint mode of this graphics context to alternate between this graphics context's current color and the new specified color. |
String |
toString
Returns a String object representing this
Graphics object's value. |
abstract void |
translate
Translates the origin of the graphics context to the point (x, y) in the current coordinate system. |
Methods inherited from class java.lang.Object ![]() |
|---|
clone |
| Constructor Detail |
|---|

protected Graphics()
Graphics object.
This constructor is the default contructor for a graphics
context.
Since Graphics is an abstract class, applications
cannot call this constructor directly. Graphics contexts are
obtained from other graphics contexts or are created by calling
getGraphics on a component.
create()
,
Component.getGraphics()

| Method Detail |
|---|

public abstract Graphics![]()
![]()
create()
Graphics object that is
a copy of this Graphics object.

public Graphics![]()
![]()
create(int x, int y, int width, int height)
Graphics object based on this
Graphics object, but with a new translation and clip area.
The new Graphics object has its origin
translated to the specified point (x, y).
Its clip area is determined by the intersection of the original
clip area with the specified rectangle. The arguments are all
interpreted in the coordinate system of the original
Graphics object. The new graphics context is
identical to the original, except in two respects:
0, 0) in the
new graphics context is the same as (x, y) in
the original graphics context.
0, 0), and its size
is specified by the width and height
arguments.
x - the x coordinate.y - the y coordinate.width - the width of the clipping rectangle.height - the height of the clipping rectangle.
translate(int, int)
,
clipRect(int, int, int, int)


public abstract void translate(int x,
int y)
x - the x coordinate.y - the y coordinate.

public abstract Color![]()
![]()
getColor()
Color
,
setColor(Color)


public abstract void setColor(Color![]()
![]()
c)
c - the new rendering color.Color
,
getColor()


public abstract void setPaintMode()

public abstract void setXORMode(Color![]()
![]()
c1)
When drawing operations are performed, pixels which are the current color are changed to the specified color, and vice versa.
Pixels that are of colors other than those two colors are changed in an unpredictable but reversible manner; if the same figure is drawn twice, then all pixels are restored to their original values.
c1 - the XOR alternation color

public abstract Font![]()
![]()
getFont()
Font
,
setFont(Font)


public abstract void setFont(Font![]()
![]()
font)
font - the font.getFont()
,
drawString(java.lang.String, int, int)
,
drawBytes(byte[], int, int, int, int)
,
drawChars(char[], int, int, int, int)


public FontMetrics![]()
![]()
getFontMetrics()
getFont()
,
FontMetrics
,
getFontMetrics(Font)


public abstract FontMetrics![]()
![]()
getFontMetrics(Font
![]()
![]()
f)
f - the specified font
getFont()
,
FontMetrics
,
getFontMetrics()
