//file ShapesPaths.java // showing off primitives import java.awt.*; import java.awt.event.*; import java.awt.geom.*; import javax.swing.*; import java.util.Random; public class MorePaths extends JComponent { public void paint(Graphics g) { Graphics2D g2 = (Graphics2D)g; int wd = getSize().width; int ht = getSize().height; //System.out.println(wd); //System.out.println(ht); GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD); //GeneralPath linePath = new GeneralPath(GeneralPath.WIND_NON_ZERO); path.moveTo(200,200); path.lineTo(280,172); path.curveTo(400,40,560,320,640,320); path.lineTo(800,224); path.quadTo(400,600,280,240); path.closePath(); g2.setPaint(Color.yellow); g2.fill(path); // g2.setPaint(Color.black); // g2.draw(path); // //// bounding box // g2.setPaint(Color.black); // Rectangle2D bounds = path.getBounds2D(); // g2.draw(bounds); // //// line vertices black // g2.setPaint(Color.black); // g2.fill(new Ellipse2D.Double(195,195,10,10)); // g2.fill(new Ellipse2D.Double(275,167,10,10)); //// cubic Bezier boundary lines red // g2.setPaint(Color.red); // g2.drawLine(280,172,400,40); // g2.drawLine(400,40,560,320); // g2.drawLine(560,320,640,320); //// line vertices black // g2.setPaint(Color.black); // g2.fill(new Ellipse2D.Double(635,315,10,10)); // g2.fill(new Ellipse2D.Double(795,219,10,10)); //// quadratic Bezier boundary lines red // g2.setPaint(Color.red); // g2.drawLine(800,224,400,600); // g2.drawLine(400,600,280,240); //// closepath line vertices black // g2.setPaint(Color.black); // g2.fill(new Ellipse2D.Double(275,235,10,10)); // g2.fill(new Ellipse2D.Double(195,195,10,10)); } //========================================================== Shape aShape(int wd, int ht) { GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD); //GeneralPath linePath = new GeneralPath(GeneralPath.WIND_NON_ZERO); path.moveTo(200,200); path.lineTo(280,172); path.curveTo(400,40,560,320,640,320); path.lineTo(800,224); path.quadTo(400,600,280,240); path.closePath(); return path; } public static void main(String[] args){ JFrame f = new JFrame("MorePaths"); Container c = f.getContentPane(); c.setLayout(new BorderLayout()); c.add(new MorePaths(), BorderLayout.CENTER); f.setSize(900, 822); f.addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e) { System.exit(0); } }); f.setVisible(true); } }