1 18 package org.apache.batik.svggen; 19 20 import java.awt.*; 21 import java.awt.geom.*; 22 23 30 public class BasicShapes implements Painter { 31 public void paint(Graphics2D g){ 32 g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, 33 RenderingHints.VALUE_ANTIALIAS_ON); 34 35 g.setPaint(Color.black); 36 37 g.drawString("Rectangle", 10, 20); 39 Rectangle rect = new Rectangle(10, 30, 50, 40); 40 g.draw(rect); 41 42 g.translate(0, 90); 43 44 g.drawString("RoundRectangle", 10, 20); 46 RoundRectangle2D roundRect = new RoundRectangle2D.Double(10, 30, 50, 40, 10, 10); 47 g.draw(roundRect); 48 49 g.translate(0, 90); 50 51 g.drawString("Circle", 10, 20); 53 Ellipse2D circle = new Ellipse2D.Float(10, 30, 50, 50); 54 g.draw(circle); 55 56 g.translate(0, 90); 57 58 g.drawString("CubicCurve2D", 10, 20); 60 CubicCurve2D curve = new CubicCurve2D.Float(10, 55, 22.5f, 00, 38.5f, 110, 60, 55); 61 g.draw(curve); 62 63 g.translate(150, -270); 64 65 g.drawString("Polygon", 10, 20); 67 Polygon polygon = new Polygon(new int[] { 30, 50, 10 }, 68 new int[] { 30, 60, 60 }, 69 3); 70 g.draw(polygon); 71 72 g.translate(0, 90); 73 74 g.drawString("GeneralPath", 10, 20); 76 GeneralPath path = new GeneralPath(); 77 path.moveTo(30, 30); 78 path.quadTo(30, 50, 50, 60); 79 path.quadTo(30, 50, 10, 60); 80 path.quadTo(30, 50, 30, 30); 81 path.closePath(); 82 g.draw(path); 83 84 g.translate(0, 90); 85 86 g.drawString("Area", 10, 20); 88 Area area = new Area(new Rectangle(10, 30, 50, 50)); 89 area.subtract(new Area(new Ellipse2D.Double(12, 32, 46, 46))); 90 g.fill(area); 91 92 g.translate(0, 90); 93 94 g.drawString("QuadCurve2D", 10, 20); 96 QuadCurve2D quad = new QuadCurve2D.Float(10, 55, 35, 105, 60, 55); 97 g.draw(quad); 98 99 g.translate(-75, 70); 100 101 g.drawString("Line2D", 10, 20); 103 g.draw(new Line2D.Float(10, 30, 60, 30)); 104 } 105 } 106 | Popular Tags |