Refine search
Path2D path = new Path2D.Double(); x += .5; int lineLength = 18; path.moveTo(x + lineLength, y); path.lineTo(x, y); path.lineTo(x, y + height); path.lineTo(x + lineLength, y + height); path.lineTo(x + lineLength, y + height - 1); path.lineTo(x + 1, y + height - 1); path.lineTo(x + 1, y + 1); path.lineTo(x + lineLength, y + 1); path.closePath();
@Implementation(minSdk = LOLLIPOP) protected void addRoundRect( float left, float top, float right, float bottom, float[] radii, Path.Direction dir) { if (radii.length < 8) { throw new ArrayIndexOutOfBoundsException("radii[] needs 8 values"); } isSimplePath = false; float[] cornerDimensions = new float[radii.length]; for (int i = 0; i < radii.length; i++) { cornerDimensions[i] = 2 * radii[i]; } mPath.append( new RoundRectangle(left, top, right - left, bottom - top, cornerDimensions), false); }
private static void addPath(Path destPath, Path srcPath, AffineTransform transform) { if (destPath == null) { return; } if (srcPath == null) { return; } ShadowPath shadowDestPath = extract(destPath); ShadowPath shadowSrcPath = extract(srcPath); if (transform != null) { shadowDestPath.mPath.append(shadowSrcPath.mPath.getPathIterator(transform), false); } else { shadowDestPath.mPath.append(shadowSrcPath.mPath, false); } }
int pathSegmentType = pi.currentSegment(coords); int windingRule = pi.getWindingRule(); gp.setWindingRule(windingRule); if (pathSegmentType == PathIterator.SEG_MOVETO) { gp = new GeneralPath(); gp.setWindingRule(windingRule); gp.moveTo(coords[0], coords[1]); System.out.println(ii++ + " \t" + coords[0] + "," + coords[1]); coords[4], coords[5]); } else if (pathSegmentType == PathIterator.SEG_CLOSE) { gp.closePath(); regions.add(new Area(gp)); } else { if (r1.getX() < 0.001 && r1.getY() < 0.001) { } else { g.setColor(bgColor); g.setColor(outlineColor); g.fill(shapeArea); g.dispose(); l.setBackground(bg); l.setOpaque(true); c.add(l);
private static final Color ROSE_COLOR = Color.red; private static final Stroke ROSE_STROKE = new BasicStroke(8f); private Path2D path = new Path2D.Double(); double dY = SCALE * r * Math.sin(theta) + DELTA_Y; if (i == 0) { path.moveTo(dX, dY); } else { path.lineTo(dX, dY); path.closePath(); super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(ROSE_COLOR); g2.setStroke(ROSE_STROKE); g2.draw(path); RosePanel mainPanel = new RosePanel(); JFrame frame = new JFrame("RosePanel"); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.getContentPane().add(mainPanel); frame.pack(); frame.setLocationByPlatform(true); frame.setVisible(true);
public void run() { ClickNTurn ex = new ClickNTurn(); ex.setVisible(true); setDefaultCloseOperation(EXIT_ON_CLOSE); getContentPane().setBackground(Color.RED); add(new Entry()); pack(); setDefaultCloseOperation(EXIT_ON_CLOSE); super.paintComponent(g); Path2D p = new Path2D.Float(); p.moveTo(getWidth() / 4, getHeight() / 4); p.lineTo(getWidth() - (getWidth() / 4), getHeight() / 2); p.lineTo(getWidth() / 4, getHeight() - (getHeight() / 4)); p.closePath(); Graphics2D g2d = (Graphics2D) g.create(); g2d.setColor(Color.GREEN); g2d.rotate(Math.toRadians(rotationAngle), getWidth() / 2, getHeight() / 2); g2d.fill(p); g2d.dispose();
private static final Color COLOR_2 = Color.red; private static final Paint GRADIENT_PAINT = new GradientPaint(0, 0, COLOR_1, 20, 20, COLOR_2, true); private Path2D myPath = new Path2D.Double(); double firstY = 3.0 * PREF_H / 4.0; myPath.moveTo(firstX, firstY); myPath.lineTo(PREF_W - firstX, firstY); myPath.lineTo(PREF_W / 2.0, PREF_H / 4.0); myPath.closePath(); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setPaint(GRADIENT_PAINT); // just for fun! g2.fill(myPath); // fill my triangle Path2DExample mainPanel = new Path2DExample(); JFrame frame = new JFrame("Path2DExample"); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.getContentPane().add(mainPanel); frame.pack(); frame.setLocationByPlatform(true); frame.setVisible(true);
JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(new ShapeOutlineTestPanel()); f.setSize(500, 500); f.setLocationRelativeTo(null); f.setVisible(true); g.setStroke(traceStroke); g.setColor(Color.BLUE); g.drawPolyline(xs, ys, 6); Path2D path = new Path2D.Double(); for (int i = 0; i < xs.length; i++) path.moveTo(xs[i], ys[i]); path.lineTo(xs[i], ys[i]); g.setColor(Color.RED); BasicStroke stroke = new BasicStroke( 10.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND); g.draw(new Area(stroke.createStrokedShape(path)));
Graphics2D g2d = (Graphics2D) g.create(); g2d.setColor(getColor()); g2d.setStroke(getStroke()); Path2D path = buildPath(points); g2d.draw(path); g2d.dispose(); Path2D path = new Path2D.Double(); if (points != null && points.size() > 0) { Point firstPoint = points.get(0); path.moveTo(firstPoint.getX(), firstPoint.getY()); for (Point p : points) { path.lineTo(p.getX(), p.getY()); JFrame frame = new JFrame("Demo"); JMapViewer viewer = new JMapViewer(); viewer.addMapPolygon(polyLine); frame.add(viewer); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLocationByPlatform(true); frame.pack(); frame.setVisible(true);
@SuppressWarnings("serial") public static void main(String[] args) { JFrame f = new JFrame("Test"); JPanel c = new JPanel() { Area a; Path2D p; p = new Path2D.Double(); p.append(new CubicCurve2D.Double(0, 0, 100, 0, 150, 50, 200, 100), true); p.append(new CubicCurve2D.Double(200, 100, 200, 150, 150,0, 50, 100), true); p.append(new CubicCurve2D.Double(100, 100, 100, 50, 50, 50, 0, 0), true); a = new Area(p); setPreferredSize(new Dimension(300, 300)); g.setColor(Color.black); ((Graphics2D)g).fill(p); System.out.println(a.isSingular()); f.setContentPane(c); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.pack(); f.setVisible(true);
JFrame frame = new JFrame("Testing"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); frame.add(new TestPane()); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g.create(); g2d.setColor(Color.RED); g2d.fill(poly); g2d.setColor(Color.GREEN); g2d.translate(50, 100); g2d.fill(triangleShape); g2d.dispose(); moveTo(points[0].getX(), points[0].getY()); lineTo(points[1].getX(), points[1].getY()); lineTo(points[2].getX(), points[2].getY()); closePath();
JFrame frame = new JFrame("Testing"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(new TestPane()); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g.create(); int x = (getWidth() - diamond.getBounds().width) / 2; int y = (getHeight()- diamond.getBounds().height) / 2; AffineTransform at = AffineTransform.getTranslateInstance(x, y); Shape shape = at.createTransformedShape(diamond); g2d.setColor(Color.YELLOW); g2d.fill(shape); g2d.setColor(Color.RED); g2d.draw(shape); g2d.dispose(); moveTo(0, height / 2); lineTo(width / 2, 0); lineTo(width, height / 2); lineTo(width / 2, height); closePath();
JFrame frame = new JFrame("Testing"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(new TestPane()); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); int x = (getWidth() - 100) / 2; int y = (getHeight()- 100) / 2; Graphics2D g2d = (Graphics2D) g.create(); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.translate(x, y); g2d.fill(rightEnd); g2d.dispose(); curveTo(width, height, width, height, width - radius, height); lineTo(0, height); closePath();
g.setColor(Color.RED); ((Graphics2D) g).fill(bend); Path2D.Double bend2 = new Path2D.Double(); bend2.moveTo(0, 50); bend2.quadTo(0, 0, 50, 0); bend2.lineTo(50, 25); bend2.quadTo(25, 25, 25, 50); bend2.closePath(); g.setColor(Color.GREEN); ((Graphics2D) g).fill(bend2); Area bend3 = new Area(outerArc); bend3.subtract(new Area(innerArc)); g.setColor(Color.BLUE); ((Graphics2D) g).fill(bend3); @Override public void run() { JFrame frame = new JFrame("Test"); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.getContentPane().add(new TestDonut()); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true);
star.lineTo(xPoints[count], yPoints[count]); star.closePath(); g2d.translate(150, 150); for (int count = 1; count <= 20; count++) { g2d.rotate(Math.PI / 10.0); g2d.setColor(new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256))); g2d.fill(star); JFrame frame = new JFrame("Drawing 2D Shapes"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Shapes2JPanel shapes2JPanel = new Shapes2JPanel(); frame.add(shapes2JPanel); // add shapes2JPanel to frame frame.setSize(315, 330); // set frame size frame.setVisible(true); // display frame
q.setCurve(10, 30, 10, 200, 100, 100); g2.draw(q); g2.fill(q); closedCurve.moveTo(0, 300); closedCurve.lineTo(0, 200); closedCurve.append(q2, true); closedCurve.lineTo(300, 300); closedCurve.closePath(); g2.draw(closedCurve); g2.fill(closedCurve); JFrame window = new JFrame(); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); window.setBounds(30, 30, 300, 320); window.getContentPane().add(new MyCanvas()); window.setVisible(true);
BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB); Graphics2D g = (Graphics2D) image.getGraphics(); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setColor(Color.WHITE); g.fillRect(0, 0, 100, 100); g.setColor(Color.BLACK); g.setStroke(new BasicStroke(2)); Path2D path = new Path2D.Double(); path.moveTo(-92, 37); path.lineTo(88, 39); g.draw(path); g.dispose(); ImageIO.write(image, "png", new File("output.png"));
JFrame frame = new JFrame("Testing"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(new TestPane()); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); moveTo(54, 0); lineTo(66, 36); lineTo(108, 36); lineTo(75, 54); lineTo(82, 96); lineTo(0, 36); lineTo(42, 36); closePath(); protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g.create(); Rectangle bounds = starShape.getBounds(); int x = (getWidth() - bounds.width) / 2; int y = (getHeight() - bounds.height) / 2; g2d.fill(starShape.createTransformedShape(AffineTransform.getTranslateInstance(x, y))); g2d.dispose();