java.awt

Class Graphics

  • java.lang.Object
    • java.awt.Graphics
  • Direct Known Subclasses:
    Graphics2D
    public abstract class Graphics extends java.lang.Object
    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:

    • The Component object on which to draw.
    • A translation origin for rendering and clipping coordinates.
    • The current clip.
    • The current color.
    • The current font.
    • The current logical pixel operation function (XOR or Paint).
    • The current XOR alternation color (see 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:

    • If you draw a figure that covers a given rectangle, that figure occupies one extra row of pixels on the right and bottom edges as compared to filling a figure that is bounded by that same rectangle.
    • If you draw a horizontal line along the same y coordinate as the baseline of a line of text, that line is drawn entirely below the text, except for any descenders.

    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.

    Since:
    JDK1.0
    See Also:
    Component, clipRect(int, int, int, int), setColor(java.awt.Color), setPaintMode(), setXORMode(java.awt.Color), setFont(java.awt.Font)
    • Methods 
      Modifier and Type Method and Description
      Ordinary member indicator clearRect Reveal DetailHide Detail
      Clears the specified rectangle by filling it with the background color of the current drawing surface.
      Ordinary member indicator clipRect Reveal DetailHide Detail
      Intersects the current clip with the specified rectangle.
      Ordinary member indicator copyArea Reveal DetailHide Detail
      Copies an area of the component by a distance specified by dx and dy.
      Ordinary member indicator create Reveal DetailHide Detail
      Creates a new Graphics object that is a copy of this Graphics object.
      Ordinary member indicator create Reveal DetailHide Detail
      Creates a new Graphics object based on this Graphics object, but with a new translation and clip area.
      Ordinary member indicator dispose Reveal DetailHide Detail
      Disposes of this graphics context and releases any system resources that it is using.
      Ordinary member indicator draw3DRect Reveal DetailHide Detail
      Draws a 3-D highlighted outline of the specified rectangle.
      Ordinary member indicator drawArc Reveal DetailHide Detail
      Draws the outline of a circular or elliptical arc covering the specified rectangle.
      Ordinary member indicator drawBytes Reveal DetailHide Detail
      Draws the text given by the specified byte array, using this graphics context's current font and color.
      Ordinary member indicator drawChars Reveal DetailHide Detail
      Draws the text given by the specified character array, using this graphics context's current font and color.
      Ordinary member indicator drawImage Reveal DetailHide Detail
      Draws as much of the specified image as is currently available.
      Ordinary member indicator drawImage Reveal DetailHide Detail
      Draws as much of the specified image as is currently available.
      Ordinary member indicator drawImage Reveal DetailHide Detail
      Draws as much of the specified image as has already been scaled to fit inside the specified rectangle.
      Ordinary member indicator drawImage Reveal DetailHide Detail
      Draws as much of the specified image as has already been scaled to fit inside the specified rectangle.
      Ordinary member indicator drawImage Reveal DetailHide Detail
      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.
      Ordinary member indicator drawImage Reveal DetailHide Detail
      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.
      Ordinary member indicator drawLine Reveal DetailHide Detail
      Draws a line, using the current color, between the points (x1, y1) and (x2, y2) in this graphics context's coordinate system.
      Ordinary member indicator drawOval Reveal DetailHide Detail
      Draws the outline of an oval.
      Ordinary member indicator drawPolygon Reveal DetailHide Detail
      Draws a closed polygon defined by arrays of x and y coordinates.
      Ordinary member indicator drawPolygon Reveal DetailHide Detail
      Draws the outline of a polygon defined by the specified Polygon object.
      Ordinary member indicator drawPolyline Reveal DetailHide Detail
      Draws a sequence of connected lines defined by arrays of x and y coordinates.
      Ordinary member indicator drawRect Reveal DetailHide Detail
      Draws the outline of the specified rectangle.
      Ordinary member indicator drawRoundRect Reveal DetailHide Detail
      Draws an outlined round-cornered rectangle using this graphics context's current color.
      Ordinary member indicator drawString Reveal DetailHide Detail
      Renders the text of the specified iterator applying its attributes in accordance with the specification of the TextAttribute class.
      Ordinary member indicator drawString Reveal DetailHide Detail
      Draws the text given by the specified string, using this graphics context's current font and color.
      Ordinary member indicator fill3DRect Reveal DetailHide Detail
      Paints a 3-D highlighted rectangle filled with the current color.
      Ordinary member indicator fillArc Reveal DetailHide Detail
      Fills a circular or elliptical arc covering the specified rectangle.
      Ordinary member indicator fillOval Reveal DetailHide Detail
      Fills an oval bounded by the specified rectangle with the current color.
      Ordinary member indicator fillPolygon Reveal DetailHide Detail
      Fills a closed polygon defined by arrays of x and y coordinates.
      Ordinary member indicator fillPolygon Reveal DetailHide Detail
      Fills the polygon defined by the specified Polygon object with the graphics context's current color.
      Ordinary member indicator fillRect Reveal DetailHide Detail
      Fills the specified rectangle.
      Ordinary member indicator fillRoundRect Reveal DetailHide Detail
      Fills the specified rounded corner rectangle with the current color.
      Overridden member indicator finalize Reveal DetailHide Detail
      Disposes of this graphics context once it is no longer referenced.
      Ordinary member indicator getClip Reveal DetailHide Detail
      Gets the current clipping area.
      Ordinary member indicator getClipBounds Reveal DetailHide Detail
      Returns the bounding rectangle of the current clipping area.
      Ordinary member indicator getClipBounds Reveal DetailHide Detail
      Returns the bounding rectangle of the current clipping area.
      Ordinary member indicator getClipRect Reveal DetailHide Detail
      Deprecated. As of JDK version 1.1, replaced by getClipBounds().
      Ordinary member indicator getColor Reveal DetailHide Detail
      Gets this graphics context's current color.
      Ordinary member indicator getFont Reveal DetailHide Detail
      Gets the current font.
      Ordinary member indicator getFontMetrics Reveal DetailHide Detail
      Gets the font metrics of the current font.
      Ordinary member indicator getFontMetrics Reveal DetailHide Detail
      Gets the font metrics for the specified font.
      Ordinary member indicator hitClip Reveal DetailHide Detail
      Returns true if the specified rectangular area might intersect the current clipping area.
      Ordinary member indicator setClip Reveal DetailHide Detail
      Sets the current clip to the rectangle specified by the given coordinates.
      Ordinary member indicator setClip Reveal DetailHide Detail
      Sets the current clipping area to an arbitrary clip shape.
      Ordinary member indicator setColor Reveal DetailHide Detail
      Sets this graphics context's current color to the specified color.
      Ordinary member indicator setFont Reveal DetailHide Detail
      Sets this graphics context's font to the specified font.
      Ordinary member indicator setPaintMode Reveal DetailHide Detail
      Sets the paint mode of this graphics context to overwrite the destination with this graphics context's current color.
      Ordinary member indicator setXORMode Reveal DetailHide Detail
      Sets the paint mode of this graphics context to alternate between this graphics context's current color and the new specified color.
      Overridden member indicator toString Reveal DetailHide Detail
      Returns a String object representing this Graphics object's value.
      Ordinary member indicator translate Reveal DetailHide Detail
      Translates the origin of the graphics context to the point (xy) in the current coordinate system.
      • Methods inherited from class java.lang.Object

        clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
This document was created by Dulcet from the OpenJDK sources. Copyright © 1993, 2012 Oracle and/or its affiliates. All rights reserved.

SourceForge