📄 graphics.java
字号:
/* * @(#)Graphics.java 1.62 06/10/10 * * Copyright 1990-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version * 2 only, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License version 2 for more details (a copy is * included at /legal/license.txt). * * You should have received a copy of the GNU General Public License * version 2 along with this work; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa * Clara, CA 95054 or visit www.sun.com if you need additional * information or have any questions. * */package java.awt;import java.io.*;import java.lang.*;import java.util.*;import java.awt.image.ImageObserver;import java.text.AttributedCharacterIterator;/** * The <code>Graphics</code> 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. * <p> * A <code>Graphics</code> object encapsulates state information needed * for the basic rendering operations that Java supports. This * state information includes the following properties: * <p> * <ul> * <li>The <code>Component</code> object on which to draw. * <li>A translation origin for rendering and clipping coordinates. * <li>The current clip. * <li>The current color. * <li>The current font. * <li>The current logical pixel operation function (XOR or Paint). * <li>The current XOR alternation color * (see <a href="#setXORMode"><code>setXORMode</code></a>). * </ul> * <p> * Coordinates are infinitely thin and lie between the pixels of the * output device. * Operations which 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 which fill a figure operate by filling the interior * of that infinitely thin path. * Operations which render horizontal text render the ascending * portion of character glyphs entirely above the baseline coordinate. * <p> * The graphics pen hangs down and to the right from the path it traverses. * This has the following implications: * <p><ul> * <li>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. * <li>If you draw a horizontal line along the same <i>y</i> coordinate as * the baseline of a line of text, that line is drawn entirely below * the text, except for any descenders. * </ul><p> * All coordinates which appear as arguments to the methods of this * <code>Graphics</code> object are considered relative to the * translation origin of this <code>Graphics</code> object prior to * the invocation of the method. * All rendering operations modify only pixels which lie within the * area bounded by both the current clip of the graphics context * and the extents of the component used to create the * <code>Graphics</code> object. * All drawing or writing is done in the current color, * using the current paint mode, and in the current font. * <h3>Compatibility</h3> * The Graphics class is compatible with the graphics class in * PersonalJava. It has modified behavior from JDK1.1.8, in that * its setXorMode may not have any effect. * * @version 1.54, 02/20/02 * @author Sami Shaio * @author Arthur van Hoff * @see java.awt.Component * @see java.awt.Graphics#clipRect(int, int, int, int) * @see java.awt.Graphics#setColor(java.awt.Color) * @see java.awt.Graphics#setPaintMode() * @see java.awt.Graphics#setXORMode(java.awt.Color) * @see java.awt.Graphics#setFont(java.awt.Font) * @since JDK1.0 */public abstract class Graphics { /** * Constructs a new <code>Graphics</code> object. * This constructor is the default contructor for a graphics * context. * <p> * Since <code>Graphics</code> is an abstract class, applications * cannot call this constructor directly. Graphics contexts are * obtained from other graphics contexts or are created by calling * <code>getGraphics</code> on a component. * @see java.awt.Graphics#create() * @see java.awt.Component#getGraphics * @since JDK1.0 */ protected Graphics() {} /** * Creates a new <code>Graphics</code> object that is * a copy of this <code>Graphics</code> object. * @return a new graphics context that is a copy of * this graphics context. * @since JDK1.0 */ public abstract Graphics create(); /** * Creates a new <code>Graphics</code> object based on this * <code>Graphics</code> object, but with a new translation and clip area. * The new <code>Graphics</code> object has its origin * translated to the specified point (<i>x</i>, <i>y</i>). * 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 * <code>Graphics</code> object. The new graphics context is * identical to the original, except in two respects: * <p> * <ul> * <li> * The new graphics context is translated by (<i>x</i>, <i>y</i>). * That is to say, the point (<code>0</code>, <code>0</code>) in the * new graphics context is the same as (<i>x</i>, <i>y</i>) in * the original graphics context. * <li> * The new graphics context has an additional clipping rectangle, in * addition to whatever (translated) clipping rectangle it inherited * from the original graphics context. The origin of the new clipping * rectangle is at (<code>0</code>, <code>0</code>), and its size * is specified by the <code>width</code> and <code>height</code> arguments. * </ul> * <p> * @param x the <i>x</i> coordinate. * @param y the <i>y</i> coordinate. * @param width the width of the clipping rectangle. * @param height the height of the clipping rectangle. * @return a new graphics context. * @see java.awt.Graphics#translate * @see java.awt.Graphics#clipRect * @since JDK1.0 */ public Graphics create(int x, int y, int width, int height) { Graphics g = create(); g.translate(x, y); g.clipRect(0, 0, width, height); return g; } /** * Translates the origin of the graphics context to the point * (<i>x</i>, <i>y</i>) in the current coordinate system. * Modifies this graphics context so that its new origin corresponds * to the point (<i>x</i>, <i>y</i>) in this graphics context's * original coordinate system. All coordinates used in subsequent * rendering operations on this graphics context will be relative * to this new origin. * @param x the <i>x</i> coordinate. * @param y the <i>y</i> coordinate. * @since JDK1.0 */ public abstract void translate(int x, int y); /** * Gets this graphics context's current color. * @return this graphics context's current color. * @see java.awt.Color * @see java.awt.Graphics#setColor * @since JDK1.0 */ public abstract Color getColor(); /** * Sets this graphics context's current color to the specified * color. All subsequent graphics operations using this graphics * context use this specified color. * @param c the new rendering color. * @see java.awt.Color * @see java.awt.Graphics#getColor * @since JDK1.0 */ public abstract void setColor(Color c); /** * Sets the paint mode of this graphics context to overwrite the * destination with this graphics context's current color. * This sets the logical pixel operation function to the paint or * overwrite mode. All subsequent rendering operations will * overwrite the destination with the current color. * @since JDK1.0 */ public abstract void setPaintMode(); /** * This method sets the graphics context to xor paint mode using * the "exclusive or" color xorcolor. * This specifies that logical pixel operations are performed in the * XOR mode, which alternates pixels between the current color and * a specified XOR color. * <p> * When drawing operations are performed, pixels which are the * current color are changed to the specified color, and vice versa. * <p> * 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. * <h3>Compatibility</h3> * Both PersonalJava and Personal Profile implementations are not required * to support this method. * <h3>System Properties</h3> * The System Property <code>java.awt.graphics.SupportsXorMode</code> is set to * <code>"true"</code> or <code>"false"</code> indicating if the platform supports * XOR rendering. * @param c1 the XOR alternation color * @exception <code>UnsupportedOperationException</code> if the implementation does * not support an XOR paint mode. * @since JDK1.0 */ public abstract void setXORMode(Color c1); /** * Gets the current font. * @return this graphics context's current font. * @see java.awt.Font * @see java.awt.Graphics#setFont * @since JDK1.0 */ public abstract Font getFont(); /** * Sets this graphics context's font to the specified font. * All subsequent text operations using this graphics context * use this font. * @param font the font. * @see java.awt.Graphics#getFont * @see java.awt.Graphics#drawChars * @see java.awt.Graphics#drawString * @see java.awt.Graphics#drawBytes * @since JDK1.0 */ public abstract void setFont(Font font); /** * Gets the font metrics of the current font. * @return the font metrics of this graphics * context's current font. * @see java.awt.Graphics#getFont * @see java.awt.FontMetrics * @see java.awt.Graphics#getFontMetrics(Font) * @since JDK1.0 */ public FontMetrics getFontMetrics() { return getFontMetrics(getFont()); } /** * Gets the font metrics for the specified font. * @return the font metrics for the specified font. * @param f the specified font * @see java.awt.Graphics#getFont * @see java.awt.FontMetrics * @see java.awt.Graphics#getFontMetrics() * @since JDK1.0 */ public abstract FontMetrics getFontMetrics(Font f); /** * Returns the bounding rectangle of the current clipping area. * The coordinates in the rectangle are relative to the coordinate * system origin of this graphics context. * @return the bounding rectangle of the current clipping area. * @see java.awt.Graphics#getClip * @see java.awt.Graphics#clipRect * @see java.awt.Graphics#setClip(int, int, int, int) * @see java.awt.Graphics#setClip(Shape) * @since JDK1.1
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -