< prev index next >

src/java.desktop/share/classes/java/awt/Graphics.java

Print this page


   1 /*
   2  * Copyright (c) 1995, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 679      * @param        startAngle the beginning angle.
 680      * @param        arcAngle the angular extent of the arc,
 681      *                    relative to the start angle.
 682      * @see         java.awt.Graphics#drawArc
 683      */
 684     public abstract void fillArc(int x, int y, int width, int height,
 685                                  int startAngle, int arcAngle);
 686 
 687     /**
 688      * Draws a sequence of connected lines defined by
 689      * arrays of <i>x</i> and <i>y</i> coordinates.
 690      * Each pair of (<i>x</i>,&nbsp;<i>y</i>) coordinates defines a point.
 691      * The figure is not closed if the first point
 692      * differs from the last point.
 693      * @param       xPoints an array of <i>x</i> points
 694      * @param       yPoints an array of <i>y</i> points
 695      * @param       nPoints the total number of points
 696      * @see         java.awt.Graphics#drawPolygon(int[], int[], int)
 697      * @since       1.1
 698      */
 699     public abstract void drawPolyline(int xPoints[], int yPoints[],
 700                                       int nPoints);
 701 
 702     /**
 703      * Draws a closed polygon defined by
 704      * arrays of <i>x</i> and <i>y</i> coordinates.
 705      * Each pair of (<i>x</i>,&nbsp;<i>y</i>) coordinates defines a point.
 706      * <p>
 707      * This method draws the polygon defined by {@code nPoint} line
 708      * segments, where the first <code>nPoint&nbsp;-&nbsp;1</code>
 709      * line segments are line segments from
 710      * <code>(xPoints[i&nbsp;-&nbsp;1],&nbsp;yPoints[i&nbsp;-&nbsp;1])</code>
 711      * to <code>(xPoints[i],&nbsp;yPoints[i])</code>, for
 712      * 1&nbsp;&le;&nbsp;<i>i</i>&nbsp;&le;&nbsp;{@code nPoints}.
 713      * The figure is automatically closed by drawing a line connecting
 714      * the final point to the first point, if those points are different.
 715      * @param        xPoints   a an array of {@code x} coordinates.
 716      * @param        yPoints   a an array of {@code y} coordinates.
 717      * @param        nPoints   a the total number of points.
 718      * @see          java.awt.Graphics#fillPolygon
 719      * @see          java.awt.Graphics#drawPolyline
 720      */
 721     public abstract void drawPolygon(int xPoints[], int yPoints[],
 722                                      int nPoints);
 723 
 724     /**
 725      * Draws the outline of a polygon defined by the specified
 726      * {@code Polygon} object.
 727      * @param        p the polygon to draw.
 728      * @see          java.awt.Graphics#fillPolygon
 729      * @see          java.awt.Graphics#drawPolyline
 730      */
 731     public void drawPolygon(Polygon p) {
 732         drawPolygon(p.xpoints, p.ypoints, p.npoints);
 733     }
 734 
 735     /**
 736      * Fills a closed polygon defined by
 737      * arrays of <i>x</i> and <i>y</i> coordinates.
 738      * <p>
 739      * This method draws the polygon defined by {@code nPoint} line
 740      * segments, where the first <code>nPoint&nbsp;-&nbsp;1</code>
 741      * line segments are line segments from
 742      * <code>(xPoints[i&nbsp;-&nbsp;1],&nbsp;yPoints[i&nbsp;-&nbsp;1])</code>
 743      * to <code>(xPoints[i],&nbsp;yPoints[i])</code>, for
 744      * 1&nbsp;&le;&nbsp;<i>i</i>&nbsp;&le;&nbsp;{@code nPoints}.
 745      * The figure is automatically closed by drawing a line connecting
 746      * the final point to the first point, if those points are different.
 747      * <p>
 748      * The area inside the polygon is defined using an
 749      * even-odd fill rule, also known as the alternating rule.
 750      * @param        xPoints   a an array of {@code x} coordinates.
 751      * @param        yPoints   a an array of {@code y} coordinates.
 752      * @param        nPoints   a the total number of points.
 753      * @see          java.awt.Graphics#drawPolygon(int[], int[], int)
 754      */
 755     public abstract void fillPolygon(int xPoints[], int yPoints[],
 756                                      int nPoints);
 757 
 758     /**
 759      * Fills the polygon defined by the specified Polygon object with
 760      * the graphics context's current color.
 761      * <p>
 762      * The area inside the polygon is defined using an
 763      * even-odd fill rule, also known as the alternating rule.
 764      * @param        p the polygon to fill.
 765      * @see          java.awt.Graphics#drawPolygon(int[], int[], int)
 766      */
 767     public void fillPolygon(Polygon p) {
 768         fillPolygon(p.xpoints, p.ypoints, p.npoints);
 769     }
 770 
 771     /**
 772      * Draws the text given by the specified string, using this
 773      * graphics context's current font and color. The baseline of the
 774      * leftmost character is at position (<i>x</i>,&nbsp;<i>y</i>) in this
 775      * graphics context's coordinate system.


 801                                     int x, int y);
 802 
 803     /**
 804      * Draws the text given by the specified character array, using this
 805      * graphics context's current font and color. The baseline of the
 806      * first character is at position (<i>x</i>,&nbsp;<i>y</i>) in this
 807      * graphics context's coordinate system.
 808      * @param data the array of characters to be drawn
 809      * @param offset the start offset in the data
 810      * @param length the number of characters to be drawn
 811      * @param x the <i>x</i> coordinate of the baseline of the text
 812      * @param y the <i>y</i> coordinate of the baseline of the text
 813      * @throws NullPointerException if {@code data} is {@code null}.
 814      * @throws IndexOutOfBoundsException if {@code offset} or
 815      * {@code length} is less than zero, or
 816      * {@code offset+length} is greater than the length of the
 817      * {@code data} array.
 818      * @see         java.awt.Graphics#drawBytes
 819      * @see         java.awt.Graphics#drawString
 820      */
 821     public void drawChars(char data[], int offset, int length, int x, int y) {
 822         drawString(new String(data, offset, length), x, y);
 823     }
 824 
 825     /**
 826      * Draws the text given by the specified byte array, using this
 827      * graphics context's current font and color. The baseline of the
 828      * first character is at position (<i>x</i>,&nbsp;<i>y</i>) in this
 829      * graphics context's coordinate system.
 830      * <p>
 831      * Use of this method is not recommended as each byte is interpreted
 832      * as a Unicode code point in the range 0 to 255, and so can only be
 833      * used to draw Latin characters in that range.
 834      * @param data the data to be drawn
 835      * @param offset the start offset in the data
 836      * @param length the number of bytes that are drawn
 837      * @param x the <i>x</i> coordinate of the baseline of the text
 838      * @param y the <i>y</i> coordinate of the baseline of the text
 839      * @throws NullPointerException if {@code data} is {@code null}.
 840      * @throws IndexOutOfBoundsException if {@code offset} or
 841      * {@code length} is less than zero, or {@code offset+length}
 842      * is greater than the length of the {@code data} array.
 843      * @see         java.awt.Graphics#drawChars
 844      * @see         java.awt.Graphics#drawString
 845      */
 846     @SuppressWarnings("deprecation")
 847     public void drawBytes(byte data[], int offset, int length, int x, int y) {
 848         drawString(new String(data, 0, offset, length), x, y);
 849     }
 850 
 851     /**
 852      * Draws as much of the specified image as is currently available.
 853      * The image is drawn with its top-left corner at
 854      * (<i>x</i>,&nbsp;<i>y</i>) in this graphics context's coordinate
 855      * space. Transparent pixels in the image do not affect whatever
 856      * pixels are already there.
 857      * <p>
 858      * This method returns immediately in all cases, even if the
 859      * complete image has not yet been loaded, and it has not been dithered
 860      * and converted for the current output device.
 861      * <p>
 862      * If the image has completely loaded and its pixels are
 863      * no longer being changed, then
 864      * {@code drawImage} returns {@code true}.
 865      * Otherwise, {@code drawImage} returns {@code false}
 866      * and as more of
 867      * the image becomes available


   1 /*
   2  * Copyright (c) 1995, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 679      * @param        startAngle the beginning angle.
 680      * @param        arcAngle the angular extent of the arc,
 681      *                    relative to the start angle.
 682      * @see         java.awt.Graphics#drawArc
 683      */
 684     public abstract void fillArc(int x, int y, int width, int height,
 685                                  int startAngle, int arcAngle);
 686 
 687     /**
 688      * Draws a sequence of connected lines defined by
 689      * arrays of <i>x</i> and <i>y</i> coordinates.
 690      * Each pair of (<i>x</i>,&nbsp;<i>y</i>) coordinates defines a point.
 691      * The figure is not closed if the first point
 692      * differs from the last point.
 693      * @param       xPoints an array of <i>x</i> points
 694      * @param       yPoints an array of <i>y</i> points
 695      * @param       nPoints the total number of points
 696      * @see         java.awt.Graphics#drawPolygon(int[], int[], int)
 697      * @since       1.1
 698      */
 699     public abstract void drawPolyline(int[] xPoints, int[] yPoints,
 700                                       int nPoints);
 701 
 702     /**
 703      * Draws a closed polygon defined by
 704      * arrays of <i>x</i> and <i>y</i> coordinates.
 705      * Each pair of (<i>x</i>,&nbsp;<i>y</i>) coordinates defines a point.
 706      * <p>
 707      * This method draws the polygon defined by {@code nPoint} line
 708      * segments, where the first <code>nPoint&nbsp;-&nbsp;1</code>
 709      * line segments are line segments from
 710      * <code>(xPoints[i&nbsp;-&nbsp;1],&nbsp;yPoints[i&nbsp;-&nbsp;1])</code>
 711      * to <code>(xPoints[i],&nbsp;yPoints[i])</code>, for
 712      * 1&nbsp;&le;&nbsp;<i>i</i>&nbsp;&le;&nbsp;{@code nPoints}.
 713      * The figure is automatically closed by drawing a line connecting
 714      * the final point to the first point, if those points are different.
 715      * @param        xPoints   a an array of {@code x} coordinates.
 716      * @param        yPoints   a an array of {@code y} coordinates.
 717      * @param        nPoints   a the total number of points.
 718      * @see          java.awt.Graphics#fillPolygon
 719      * @see          java.awt.Graphics#drawPolyline
 720      */
 721     public abstract void drawPolygon(int[] xPoints, int[] yPoints,
 722                                      int nPoints);
 723 
 724     /**
 725      * Draws the outline of a polygon defined by the specified
 726      * {@code Polygon} object.
 727      * @param        p the polygon to draw.
 728      * @see          java.awt.Graphics#fillPolygon
 729      * @see          java.awt.Graphics#drawPolyline
 730      */
 731     public void drawPolygon(Polygon p) {
 732         drawPolygon(p.xpoints, p.ypoints, p.npoints);
 733     }
 734 
 735     /**
 736      * Fills a closed polygon defined by
 737      * arrays of <i>x</i> and <i>y</i> coordinates.
 738      * <p>
 739      * This method draws the polygon defined by {@code nPoint} line
 740      * segments, where the first <code>nPoint&nbsp;-&nbsp;1</code>
 741      * line segments are line segments from
 742      * <code>(xPoints[i&nbsp;-&nbsp;1],&nbsp;yPoints[i&nbsp;-&nbsp;1])</code>
 743      * to <code>(xPoints[i],&nbsp;yPoints[i])</code>, for
 744      * 1&nbsp;&le;&nbsp;<i>i</i>&nbsp;&le;&nbsp;{@code nPoints}.
 745      * The figure is automatically closed by drawing a line connecting
 746      * the final point to the first point, if those points are different.
 747      * <p>
 748      * The area inside the polygon is defined using an
 749      * even-odd fill rule, also known as the alternating rule.
 750      * @param        xPoints   a an array of {@code x} coordinates.
 751      * @param        yPoints   a an array of {@code y} coordinates.
 752      * @param        nPoints   a the total number of points.
 753      * @see          java.awt.Graphics#drawPolygon(int[], int[], int)
 754      */
 755     public abstract void fillPolygon(int[] xPoints, int[] yPoints,
 756                                      int nPoints);
 757 
 758     /**
 759      * Fills the polygon defined by the specified Polygon object with
 760      * the graphics context's current color.
 761      * <p>
 762      * The area inside the polygon is defined using an
 763      * even-odd fill rule, also known as the alternating rule.
 764      * @param        p the polygon to fill.
 765      * @see          java.awt.Graphics#drawPolygon(int[], int[], int)
 766      */
 767     public void fillPolygon(Polygon p) {
 768         fillPolygon(p.xpoints, p.ypoints, p.npoints);
 769     }
 770 
 771     /**
 772      * Draws the text given by the specified string, using this
 773      * graphics context's current font and color. The baseline of the
 774      * leftmost character is at position (<i>x</i>,&nbsp;<i>y</i>) in this
 775      * graphics context's coordinate system.


 801                                     int x, int y);
 802 
 803     /**
 804      * Draws the text given by the specified character array, using this
 805      * graphics context's current font and color. The baseline of the
 806      * first character is at position (<i>x</i>,&nbsp;<i>y</i>) in this
 807      * graphics context's coordinate system.
 808      * @param data the array of characters to be drawn
 809      * @param offset the start offset in the data
 810      * @param length the number of characters to be drawn
 811      * @param x the <i>x</i> coordinate of the baseline of the text
 812      * @param y the <i>y</i> coordinate of the baseline of the text
 813      * @throws NullPointerException if {@code data} is {@code null}.
 814      * @throws IndexOutOfBoundsException if {@code offset} or
 815      * {@code length} is less than zero, or
 816      * {@code offset+length} is greater than the length of the
 817      * {@code data} array.
 818      * @see         java.awt.Graphics#drawBytes
 819      * @see         java.awt.Graphics#drawString
 820      */
 821     public void drawChars(char[] data, int offset, int length, int x, int y) {
 822         drawString(new String(data, offset, length), x, y);
 823     }
 824 
 825     /**
 826      * Draws the text given by the specified byte array, using this
 827      * graphics context's current font and color. The baseline of the
 828      * first character is at position (<i>x</i>,&nbsp;<i>y</i>) in this
 829      * graphics context's coordinate system.
 830      * <p>
 831      * Use of this method is not recommended as each byte is interpreted
 832      * as a Unicode code point in the range 0 to 255, and so can only be
 833      * used to draw Latin characters in that range.
 834      * @param data the data to be drawn
 835      * @param offset the start offset in the data
 836      * @param length the number of bytes that are drawn
 837      * @param x the <i>x</i> coordinate of the baseline of the text
 838      * @param y the <i>y</i> coordinate of the baseline of the text
 839      * @throws NullPointerException if {@code data} is {@code null}.
 840      * @throws IndexOutOfBoundsException if {@code offset} or
 841      * {@code length} is less than zero, or {@code offset+length}
 842      * is greater than the length of the {@code data} array.
 843      * @see         java.awt.Graphics#drawChars
 844      * @see         java.awt.Graphics#drawString
 845      */
 846     @SuppressWarnings("deprecation")
 847     public void drawBytes(byte[] data, int offset, int length, int x, int y) {
 848         drawString(new String(data, 0, offset, length), x, y);
 849     }
 850 
 851     /**
 852      * Draws as much of the specified image as is currently available.
 853      * The image is drawn with its top-left corner at
 854      * (<i>x</i>,&nbsp;<i>y</i>) in this graphics context's coordinate
 855      * space. Transparent pixels in the image do not affect whatever
 856      * pixels are already there.
 857      * <p>
 858      * This method returns immediately in all cases, even if the
 859      * complete image has not yet been loaded, and it has not been dithered
 860      * and converted for the current output device.
 861      * <p>
 862      * If the image has completely loaded and its pixels are
 863      * no longer being changed, then
 864      * {@code drawImage} returns {@code true}.
 865      * Otherwise, {@code drawImage} returns {@code false}
 866      * and as more of
 867      * the image becomes available


< prev index next >