1 /*
2 * Copyright (c) 1998, 2013, 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
439 public void fillArc(int x, int y, int width, int height,
440 int startAngle, int arcAngle) {
441
442 fill(new Arc2D.Float(x, y, width, height,
443 startAngle, arcAngle,
444 Arc2D.PIE));
445 }
446
447 /**
448 * Draws a sequence of connected lines defined by
449 * arrays of <i>x</i> and <i>y</i> coordinates.
450 * Each pair of (<i>x</i>, <i>y</i>) coordinates defines a point.
451 * The figure is not closed if the first point
452 * differs from the last point.
453 * @param xPoints an array of <i>x</i> points
454 * @param yPoints an array of <i>y</i> points
455 * @param nPoints the total number of points
456 * @see java.awt.Graphics#drawPolygon(int[], int[], int)
457 * @since 1.1
458 */
459 public void drawPolyline(int xPoints[], int yPoints[],
460 int nPoints) {
461
462 if (nPoints == 2) {
463 draw(new Line2D.Float(xPoints[0], yPoints[0],
464 xPoints[1], yPoints[1]));
465 } else if (nPoints > 2) {
466 Path2D path = new Path2D.Float(Path2D.WIND_EVEN_ODD, nPoints);
467 path.moveTo(xPoints[0], yPoints[0]);
468 for(int i = 1; i < nPoints; i++) {
469 path.lineTo(xPoints[i], yPoints[i]);
470 }
471 draw(path);
472 }
473 }
474
475
476 /**
477 * Draws a closed polygon defined by
478 * arrays of <i>x</i> and <i>y</i> coordinates.
479 * Each pair of (<i>x</i>, <i>y</i>) coordinates defines a point.
480 * <p>
481 * This method draws the polygon defined by {@code nPoint} line
482 * segments, where the first <code>nPoint - 1</code>
483 * line segments are line segments from
484 * <code>(xPoints[i - 1], yPoints[i - 1])</code>
485 * to <code>(xPoints[i], yPoints[i])</code>, for
486 * 1 ≤ <i>i</i> ≤ {@code nPoints}.
487 * The figure is automatically closed by drawing a line connecting
488 * the final point to the first point, if those points are different.
489 * @param xPoints a an array of {@code x} coordinates.
490 * @param yPoints a an array of {@code y} coordinates.
491 * @param nPoints a the total number of points.
492 * @see java.awt.Graphics#fillPolygon
493 * @see java.awt.Graphics#drawPolyline
494 */
495 public void drawPolygon(int xPoints[], int yPoints[],
496 int nPoints) {
497
498 draw(new Polygon(xPoints, yPoints, nPoints));
499 }
500
501 /**
502 * Draws the outline of a polygon defined by the specified
503 * {@code Polygon} object.
504 * @param p the polygon to draw.
505 * @see java.awt.Graphics#fillPolygon
506 * @see java.awt.Graphics#drawPolyline
507 */
508 public void drawPolygon(Polygon p) {
509 draw(p);
510 }
511
512 /**
513 * Fills a closed polygon defined by
514 * arrays of <i>x</i> and <i>y</i> coordinates.
515 * <p>
516 * This method draws the polygon defined by {@code nPoint} line
517 * segments, where the first <code>nPoint - 1</code>
518 * line segments are line segments from
519 * <code>(xPoints[i - 1], yPoints[i - 1])</code>
520 * to <code>(xPoints[i], yPoints[i])</code>, for
521 * 1 ≤ <i>i</i> ≤ {@code nPoints}.
522 * The figure is automatically closed by drawing a line connecting
523 * the final point to the first point, if those points are different.
524 * <p>
525 * The area inside the polygon is defined using an
526 * even-odd fill rule, also known as the alternating rule.
527 * @param xPoints a an array of {@code x} coordinates.
528 * @param yPoints a an array of {@code y} coordinates.
529 * @param nPoints a the total number of points.
530 * @see java.awt.Graphics#drawPolygon(int[], int[], int)
531 */
532 public void fillPolygon(int xPoints[], int yPoints[],
533 int nPoints) {
534
535 fill(new Polygon(xPoints, yPoints, nPoints));
536 }
537
538
539 /**
540 * Fills the polygon defined by the specified Polygon object with
541 * the graphics context's current color.
542 * <p>
543 * The area inside the polygon is defined using an
544 * even-odd fill rule, also known as the alternating rule.
545 * @param p the polygon to fill.
546 * @see java.awt.Graphics#drawPolygon(int[], int[], int)
547 */
548 public void fillPolygon(Polygon p) {
549
550 fill(p);
551 }
552
|
1 /*
2 * Copyright (c) 1998, 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
439 public void fillArc(int x, int y, int width, int height,
440 int startAngle, int arcAngle) {
441
442 fill(new Arc2D.Float(x, y, width, height,
443 startAngle, arcAngle,
444 Arc2D.PIE));
445 }
446
447 /**
448 * Draws a sequence of connected lines defined by
449 * arrays of <i>x</i> and <i>y</i> coordinates.
450 * Each pair of (<i>x</i>, <i>y</i>) coordinates defines a point.
451 * The figure is not closed if the first point
452 * differs from the last point.
453 * @param xPoints an array of <i>x</i> points
454 * @param yPoints an array of <i>y</i> points
455 * @param nPoints the total number of points
456 * @see java.awt.Graphics#drawPolygon(int[], int[], int)
457 * @since 1.1
458 */
459 public void drawPolyline(int[] xPoints, int[] yPoints,
460 int nPoints) {
461
462 if (nPoints == 2) {
463 draw(new Line2D.Float(xPoints[0], yPoints[0],
464 xPoints[1], yPoints[1]));
465 } else if (nPoints > 2) {
466 Path2D path = new Path2D.Float(Path2D.WIND_EVEN_ODD, nPoints);
467 path.moveTo(xPoints[0], yPoints[0]);
468 for(int i = 1; i < nPoints; i++) {
469 path.lineTo(xPoints[i], yPoints[i]);
470 }
471 draw(path);
472 }
473 }
474
475
476 /**
477 * Draws a closed polygon defined by
478 * arrays of <i>x</i> and <i>y</i> coordinates.
479 * Each pair of (<i>x</i>, <i>y</i>) coordinates defines a point.
480 * <p>
481 * This method draws the polygon defined by {@code nPoint} line
482 * segments, where the first <code>nPoint - 1</code>
483 * line segments are line segments from
484 * <code>(xPoints[i - 1], yPoints[i - 1])</code>
485 * to <code>(xPoints[i], yPoints[i])</code>, for
486 * 1 ≤ <i>i</i> ≤ {@code nPoints}.
487 * The figure is automatically closed by drawing a line connecting
488 * the final point to the first point, if those points are different.
489 * @param xPoints a an array of {@code x} coordinates.
490 * @param yPoints a an array of {@code y} coordinates.
491 * @param nPoints a the total number of points.
492 * @see java.awt.Graphics#fillPolygon
493 * @see java.awt.Graphics#drawPolyline
494 */
495 public void drawPolygon(int[] xPoints, int[] yPoints,
496 int nPoints) {
497
498 draw(new Polygon(xPoints, yPoints, nPoints));
499 }
500
501 /**
502 * Draws the outline of a polygon defined by the specified
503 * {@code Polygon} object.
504 * @param p the polygon to draw.
505 * @see java.awt.Graphics#fillPolygon
506 * @see java.awt.Graphics#drawPolyline
507 */
508 public void drawPolygon(Polygon p) {
509 draw(p);
510 }
511
512 /**
513 * Fills a closed polygon defined by
514 * arrays of <i>x</i> and <i>y</i> coordinates.
515 * <p>
516 * This method draws the polygon defined by {@code nPoint} line
517 * segments, where the first <code>nPoint - 1</code>
518 * line segments are line segments from
519 * <code>(xPoints[i - 1], yPoints[i - 1])</code>
520 * to <code>(xPoints[i], yPoints[i])</code>, for
521 * 1 ≤ <i>i</i> ≤ {@code nPoints}.
522 * The figure is automatically closed by drawing a line connecting
523 * the final point to the first point, if those points are different.
524 * <p>
525 * The area inside the polygon is defined using an
526 * even-odd fill rule, also known as the alternating rule.
527 * @param xPoints a an array of {@code x} coordinates.
528 * @param yPoints a an array of {@code y} coordinates.
529 * @param nPoints a the total number of points.
530 * @see java.awt.Graphics#drawPolygon(int[], int[], int)
531 */
532 public void fillPolygon(int[] xPoints, int[] yPoints,
533 int nPoints) {
534
535 fill(new Polygon(xPoints, yPoints, nPoints));
536 }
537
538
539 /**
540 * Fills the polygon defined by the specified Polygon object with
541 * the graphics context's current color.
542 * <p>
543 * The area inside the polygon is defined using an
544 * even-odd fill rule, also known as the alternating rule.
545 * @param p the polygon to fill.
546 * @see java.awt.Graphics#drawPolygon(int[], int[], int)
547 */
548 public void fillPolygon(Polygon p) {
549
550 fill(p);
551 }
552
|