java.awt
Class Graphics

java.lang.Object
  |
  +--java.awt.Graphics

public abstract class Graphics
extends Object

Graphics is the abstract base class for all graphic contexts for various devices.


Constructor Summary
protected Graphics()
          Constructs a new Graphics Object.
 
Method Summary
abstract  void clearRect(int x, int y, int width, int height)
          Clears the specified rectangle by filling it with the current background color of the current drawing surface.
abstract  void clipRect(int x, int y, int width, int height)
          Clips to a rectangle.
abstract  void copyArea(int x, int y, int width, int height, int dx, int dy)
          Copies an area of the screen.
abstract  Graphics create()
          Creates a new Graphics Object that is a copy of the original Graphics Object.
 Graphics create(int x, int y, int width, int height)
          Creates a new Graphics Object with the specified parameters, based on the original Graphics Object.
abstract  void dispose()
          Disposes of this graphics context.
 void draw3DRect(int x, int y, int width, int height, boolean raised)
          Draws a highlighted 3-D rectangle.
abstract  void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle)
          Draws an arc bounded by the specified rectangle starting at startAngle, where 0 degrees is at the 3-o'clock position, and extending for arcAngle degrees.
 void drawBytes(byte[] data, int offset, int length, int x, int y)
          Draws the specified bytes using the current font and color.
 void drawChars(char[] data, int offset, int length, int x, int y)
          Draws the specified characters using the current font and color.
abstract  boolean drawImage(Image img, int x, int y, Color bgcolor, java.awt.image.ImageObserver observer)
          Draws the specified image at the specified coordinate (x, y), with the given solid background Color.
abstract  boolean drawImage(Image img, int x, int y, java.awt.image.ImageObserver observer)
          Draws the specified image at the specified coordinate (x, y).
abstract  boolean drawImage(Image img, int x, int y, int width, int height, Color bgcolor, java.awt.image.ImageObserver observer)
          Draws the specified image inside the specified rectangle, with the given solid background Color.
abstract  boolean drawImage(Image img, int x, int y, int width, int height, java.awt.image.ImageObserver observer)
          Draws the specified image inside the specified rectangle.
abstract  void drawLine(int x1, int y1, int x2, int y2)
          Draws a line between the coordinates (x1,y1) and (x2,y2).
abstract  void drawOval(int x, int y, int width, int height)
          Draws an oval inside the specified rectangle using the current color.
abstract  void drawPolygon(int[] xPoints, int[] yPoints, int nPoints)
          Draws a polygon defined by an array of x points and y points.
 void drawPolygon(Polygon p)
          Draws a polygon defined by the specified point.
 void drawRect(int x, int y, int width, int height)
          Draws the outline of the specified rectangle using the current color.
abstract  void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
          Draws an outlined rounded corner rectangle using the current color.
abstract  void drawString(String str, int x, int y)
          Draws the specified String using the current font and color.
 void fill3DRect(int x, int y, int width, int height, boolean raised)
          Paints a highlighted 3-D rectangle using the current color.
abstract  void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle)
          Fills an arc using the current color.
abstract  void fillOval(int x, int y, int width, int height)
          Fills an oval inside the specified rectangle using the current color.
abstract  void fillPolygon(int[] xPoints, int[] yPoints, int nPoints)
          Fills a polygon with the current color using an even-odd fill rule (otherwise known as an alternating rule).
 void fillPolygon(Polygon p)
          Fills the specified polygon with the current color using an even-odd fill rule (otherwise known as an alternating rule).
abstract  void fillRect(int x, int y, int width, int height)
          Fills the specified rectangle with the current color.
abstract  void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
          Draws a rounded rectangle filled in with the current color.
 void finalize()
          Disposes of this graphics context once it is no longer referenced.
abstract  Rectangle getClipRect()
          Returns the bounding rectangle of the current clipping area.
abstract  Color getColor()
          Gets the current color.
abstract  Font getFont()
          Gets the current font.
 FontMetrics getFontMetrics()
          Gets the current font metrics.
abstract  FontMetrics getFontMetrics(Font f)
          Gets the current font metrics for the specified font.
abstract  void setColor(Color c)
          Sets the current color to the specified color.
abstract  void setFont(Font font)
          Sets the font for all subsequent text-drawing operations.
abstract  void setPaintMode()
          Sets the paint mode to overwrite the destination with the current color.
abstract  void setXORMode(Color c1)
          Sets the paint mode to alternate between the current color and the new specified color.
 String toString()
          Returns a String object representing this Graphic's value.
abstract  void translate(int x, int y)
          Translates the specified parameters into the origin of the graphics context.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Graphics

protected Graphics()
Constructs a new Graphics Object. Graphic contexts cannot be created directly. They must be obtained from another graphics context or created by a Component.

See Also:
Component.getGraphics(), create()
Method Detail

create

public abstract Graphics create()
Creates a new Graphics Object that is a copy of the original Graphics Object.


create

public Graphics create(int x,
                       int y,
                       int width,
                       int height)
Creates a new Graphics Object with the specified parameters, based on the original Graphics Object. This method translates the specified parameters, x and y, to the proper origin coordinates and then clips the Graphics Object to the area.

Parameters:
x - the x coordinate
y - the y coordinate
width - the width of the area
height - the height of the area
See Also:
translate(int, int)

translate

public abstract void translate(int x,
                               int y)
Translates the specified parameters into the origin of the graphics context. All subsequent operations on this graphics context will be relative to this origin.

Parameters:
x - the x coordinate
y - the y coordinate

getColor

public abstract Color getColor()
Gets the current color.

See Also:
setColor(java.awt.Color)

setColor

public abstract void setColor(Color c)
Sets the current color to the specified color. All subsequent graphics operations will use this specified color.

Parameters:
c - the color to be set
See Also:
Color, getColor()

setPaintMode

public abstract void setPaintMode()
Sets the paint mode to overwrite the destination with the current color.


setXORMode

public abstract void setXORMode(Color c1)
Sets the paint mode to alternate between the current color and the new specified color. When drawing operations are performed, pixels which are the current color will be changed to the specified color and vice versa. Pixels of colors other than those two colors will be changed in an unpredictable, but reversible manner - if you draw the same figure twice then all pixels will be restored to their original values.

Parameters:
c1 - the second color

getFont

public abstract Font getFont()
Gets the current font.

See Also:
setFont(java.awt.Font)

setFont

public abstract void setFont(Font font)
Sets the font for all subsequent text-drawing operations.

Parameters:
font - the specified font
See Also:
Font, getFont(), drawString(java.lang.String, int, int), drawBytes(byte[], int, int, int, int), drawChars(char[], int, int, int, int)

getFontMetrics

public FontMetrics getFontMetrics()
Gets the current font metrics.

See Also:
getFont()

getFontMetrics

public abstract FontMetrics getFontMetrics(Font f)
Gets the current font metrics for the specified font.

Parameters:
f - the specified font
See Also:
getFont(), getFontMetrics()

getClipRect

public abstract Rectangle getClipRect()
Returns the bounding rectangle of the current clipping area.

See Also:
clipRect(int, int, int, int)

clipRect

public abstract void clipRect(int x,
                              int y,
                              int width,
                              int height)
Clips to a rectangle. The resulting clipping area is the intersection of the current clipping area and the specified rectangle. Graphic operations have no effect outside of the clipping area.

Parameters:
x - the x coordinate
y - the y coordinate
width - the width of the rectangle
height - the height of the rectangle
See Also:
getClipRect()

copyArea

public abstract void copyArea(int x,
                              int y,
                              int width,
                              int height,
                              int dx,
                              int dy)
Copies an area of the screen.

Parameters:
x - the x-coordinate of the source
y - the y-coordinate of the source
width - the width
height - the height
dx - the horizontal distance
dy - the vertical distance

drawLine

public abstract void drawLine(int x1,
                              int y1,
                              int x2,
                              int y2)
Draws a line between the coordinates (x1,y1) and (x2,y2). The line is drawn below and to the left of the logical coordinates.

Parameters:
x1 - the first point's x coordinate
y1 - the first point's y coordinate
x2 - the second point's x coordinate
y2 - the second point's y coordinate

fillRect

public abstract void fillRect(int x,
                              int y,
                              int width,
                              int height)
Fills the specified rectangle with the current color.

Parameters:
x - the x coordinate
y - the y coordinate
width - the width of the rectangle
height - the height of the rectangle
See Also:
drawRect(int, int, int, int), clearRect(int, int, int, int)

drawRect

public void drawRect(int x,
                     int y,
                     int width,
                     int height)
Draws the outline of the specified rectangle using the current color. Use drawRect(x, y, width-1, height-1) to draw the outline inside the specified rectangle.

Parameters:
x - the x coordinate
y - the y coordinate
width - the width of the rectangle
height - the height of the rectangle
See Also:
fillRect(int, int, int, int), clearRect(int, int, int, int)

clearRect

public abstract void clearRect(int x,
                               int y,
                               int width,
                               int height)
Clears the specified rectangle by filling it with the current background color of the current drawing surface. Which drawing surface it selects depends on how the graphics context was created.

Parameters:
x - the x coordinate
y - the y coordinate
width - the width of the rectangle
height - the height of the rectangle
See Also:
fillRect(int, int, int, int), drawRect(int, int, int, int)

drawRoundRect

public abstract void drawRoundRect(int x,
                                   int y,
                                   int width,
                                   int height,
                                   int arcWidth,
                                   int arcHeight)
Draws an outlined rounded corner rectangle using the current color.

Parameters:
x - the x coordinate
y - the y coordinate
width - the width of the rectangle
height - the height of the rectangle
arcWidth - the horizontal diameter of the arc at the four corners
arcHeight - the horizontal diameter of the arc at the four corners
See Also:
fillRoundRect(int, int, int, int, int, int)

fillRoundRect

public abstract void fillRoundRect(int x,
                                   int y,
                                   int width,
                                   int height,
                                   int arcWidth,
                                   int arcHeight)
Draws a rounded rectangle filled in with the current color.

Parameters:
x - the x coordinate
y - the y coordinate
width - the width of the rectangle
height - the height of the rectangle
arcWidth - the horizontal diameter of the arc at the four corners
arcHeight - the horizontal diameter of the arc at the four corners
See Also:
drawRoundRect(int, int, int, int, int, int)

draw3DRect

public void draw3DRect(int x,
                       int y,
                       int width,
                       int height,
                       boolean raised)
Draws a highlighted 3-D rectangle.

Parameters:
x - the x coordinate
y - the y coordinate
width - the width of the rectangle
height - the height of the rectangle
raised - a boolean that states whether the rectangle is raised or not

fill3DRect

public void fill3DRect(int x,
                       int y,
                       int width,
                       int height,
                       boolean raised)
Paints a highlighted 3-D rectangle using the current color.

Parameters:
x - the x coordinate
y - the y coordinate
width - the width of the rectangle
height - the height of the rectangle
raised - a boolean that states whether the rectangle is raised or not

drawOval

public abstract void drawOval(int x,
                              int y,
                              int width,
                              int height)
Draws an oval inside the specified rectangle using the current color.

Parameters:
x - the x coordinate
y - the y coordinate
width - the width of the rectangle
height - the height of the rectangle
See Also:
fillOval(int, int, int, int)

fillOval

public abstract void fillOval(int x,
                              int y,
                              int width,
                              int height)
Fills an oval inside the specified rectangle using the current color.

Parameters:
x - the x coordinate
y - the y coordinate
width - the width of the rectangle
height - the height of the rectangle
See Also:
drawOval(int, int, int, int)

drawArc

public abstract void drawArc(int x,
                             int y,
                             int width,
                             int height,
                             int startAngle,
                             int arcAngle)
Draws an arc bounded by the specified rectangle starting at startAngle, where 0 degrees is at the 3-o'clock position, and extending for arcAngle degrees. Positive values for arcAngle indicate counter-clockwise rotations, negative values indicate clockwise rotations.

Parameters:
x - the x coordinate
y - the y coordinate
width - the width of the rectangle
height - the height of the rectangle
startAngle - the beginning angle
arcAngle - the angle of the arc (relative to startAngle).
See Also:
fillArc(int, int, int, int, int, int)

fillArc

public abstract void fillArc(int x,
                             int y,
                             int width,
                             int height,
                             int startAngle,
                             int arcAngle)
Fills an arc using the current color. This generates a pie shape. The extent of the arc is the same as is described for the drawArc method.

Parameters:
x - the x coordinate
y - the y coordinate
width - the width of the arc
height - the height of the arc
startAngle - the beginning angle
arcAngle - the angle of the arc (relative to startAngle).
See Also:
drawArc(int, int, int, int, int, int)

drawPolygon

public abstract void drawPolygon(int[] xPoints,
                                 int[] yPoints,
                                 int nPoints)
Draws a polygon defined by an array of x points and y points.

Parameters:
xPoints - an array of x points
yPoints - an array of y points
nPoints - the total number of points
See Also:
fillPolygon(int[], int[], int)

drawPolygon

public void drawPolygon(Polygon p)
Draws a polygon defined by the specified point.

Parameters:
p - the specified polygon
See Also:
fillPolygon(int[], int[], int)

fillPolygon

public abstract void fillPolygon(int[] xPoints,
                                 int[] yPoints,
                                 int nPoints)
Fills a polygon with the current color using an even-odd fill rule (otherwise known as an alternating rule).

Parameters:
xPoints - an array of x points
yPoints - an array of y points
nPoints - the total number of points
See Also:
drawPolygon(int[], int[], int)

fillPolygon

public void fillPolygon(Polygon p)
Fills the specified polygon with the current color using an even-odd fill rule (otherwise known as an alternating rule).

Parameters:
p - the polygon
See Also:
drawPolygon(int[], int[], int)

drawString

public abstract void drawString(String str,
                                int x,
                                int y)
Draws the specified String using the current font and color. The x,y position is the starting point of the baseline of the String.

Parameters:
str - the String to be drawn
x - the x coordinate
y - the y coordinate
See Also:
drawChars(char[], int, int, int, int), drawBytes(byte[], int, int, int, int)

drawChars

public void drawChars(char[] data,
                      int offset,
                      int length,
                      int x,
                      int y)
Draws the specified characters using the current font and color.

Parameters:
data - the array of characters to be drawn
offset - the start offset in the data
length - the number of characters to be drawn
x - the x coordinate
y - the y coordinate
See Also:
drawString(java.lang.String, int, int), drawBytes(byte[], int, int, int, int)

drawBytes

public void drawBytes(byte[] data,
                      int offset,
                      int length,
                      int x,
                      int y)
Draws the specified bytes using the current font and color.

Parameters:
data - the data to be drawn
offset - the start offset in the data
length - the number of bytes that are drawn
x - the x coordinate
y - the y coordinate
See Also:
drawString(java.lang.String, int, int), drawChars(char[], int, int, int, int)

drawImage

public abstract boolean drawImage(Image img,
                                  int x,
                                  int y,
                                  java.awt.image.ImageObserver observer)
Draws the specified image at the specified coordinate (x, y). If the image is incomplete the image observer will be notified later.

Parameters:
img - the specified image to be drawn
x - the x coordinate
y - the y coordinate
observer - notifies if the image is complete or not
See Also:
Image, ImageObserver

drawImage

public abstract boolean drawImage(Image img,
                                  int x,
                                  int y,
                                  int width,
                                  int height,
                                  java.awt.image.ImageObserver observer)
Draws the specified image inside the specified rectangle. The image is scaled if necessary. If the image is incomplete the image observer will be notified later.

Parameters:
img - the specified image to be drawn
x - the x coordinate
y - the y coordinate
width - the width of the rectangle
height - the height of the rectangle
observer - notifies if the image is complete or not
See Also:
Image, ImageObserver

drawImage

public abstract boolean drawImage(Image img,
                                  int x,
                                  int y,
                                  Color bgcolor,
                                  java.awt.image.ImageObserver observer)
Draws the specified image at the specified coordinate (x, y), with the given solid background Color. If the image is incomplete the image observer will be notified later.

Parameters:
img - the specified image to be drawn
x - the x coordinate
y - the y coordinate
observer - notifies if the image is complete or not
See Also:
Image, ImageObserver

drawImage

public abstract boolean drawImage(Image img,
                                  int x,
                                  int y,
                                  int width,
                                  int height,
                                  Color bgcolor,
                                  java.awt.image.ImageObserver observer)
Draws the specified image inside the specified rectangle, with the given solid background Color. The image is scaled if necessary. If the image is incomplete the image observer will be notified later.

Parameters:
img - the specified image to be drawn
x - the x coordinate
y - the y coordinate
width - the width of the rectangle
height - the height of the rectangle
observer - notifies if the image is complete or not
See Also:
Image, ImageObserver

dispose

public abstract void dispose()
Disposes of this graphics context. The Graphics context cannot be used after being disposed of.

See Also:
finalize()

finalize

public void finalize()
Disposes of this graphics context once it is no longer referenced.

Overrides:
finalize in class Object
See Also:
dispose()

toString

public String toString()
Returns a String object representing this Graphic's value.

Overrides:
toString in class Object