Path: blob/master/test/jdk/java/awt/BasicStroke/DashStrokeTest.java
41149 views
/*1* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22* @test23* @bug 8075942 808093224* @summary test there is no exception rendering a dashed stroke25* @run main DashStrokeTest26*/2728import java.awt.BasicStroke;29import java.awt.Color;30import java.awt.Graphics2D;31import java.awt.Stroke;32import java.awt.geom.GeneralPath;33import java.awt.image.BufferedImage;343536public class DashStrokeTest {3738public static void main(String[] args) {3940GeneralPath shape = new GeneralPath();41int[] pointTypes = {0, 0, 1, 1, 0, 1, 1, 0};42double[] xpoints = {428, 420, 400, 400, 400, 400, 420, 733};43double[] ypoints = {180, 180, 180, 160, 30, 10, 10, 10};44shape.moveTo(xpoints[0], ypoints[0]);45for (int i = 1; i < pointTypes.length; i++) {46if (pointTypes[i] == 1 && i < pointTypes.length - 1) {47shape.quadTo(xpoints[i], ypoints[i],48xpoints[i + 1], ypoints[i + 1]);49} else {50shape.lineTo(xpoints[i], ypoints[i]);51}52}5354BufferedImage image = new55BufferedImage(1000, 1000, BufferedImage.TYPE_INT_ARGB);56Graphics2D g2 = image.createGraphics();5758Color color = new Color(124, 0, 124, 255);59g2.setColor(color);60Stroke stroke = new BasicStroke(1.0f,61BasicStroke.CAP_BUTT,62BasicStroke.JOIN_BEVEL,6310.0f, new float[] {9, 6}, 0.0f);64g2.setStroke(stroke);65g2.draw(shape);66}67}686970